answerstu

bit manipulation - What are bitwise shift (bit-shift) operators and how do they work?

I've been attempting to learn C in my spare time, and other languages (C#, Java, etc.) have the same concept (and often the same operators) ... What I'm wondering is, at a core level, what does bit-shifting (<<, >>, >>>) do, what problems can it help solve, and what gotchas lurk around the bend? In other words, an absolute beginner's guide to bit shifting in all its goodness....Read more

operators - Bitwise operations, bits falling off, fit into 8 bit container

I'm trying to fit 16, 32 and 64-bit values into an 8-bit containerI'm able to shift the bits to where it's only a 8 bits of data for the container, but I do not know how to bring them back to reflect the value. I've been racking my brain all day and I cannot figure it out. Any help would be so amazing. Here's the code I've been experimenting with before I start my lab project because this is the thing that has me confused. How would I store the 8 bits and then go back and be able to pull it back up without the lost bits #include <iostream...Read more

vhdl - Verilog question mark (?) operator

I'm trying to translate a Verilog program into VHDL and have stumbled across a statement where a question mark (?) operator is used in the Verilog program.The following is the Verilog code;1 module music(clk, speaker);2 input clk;3 output speaker;4 parameter clkdivider = 25000000/440/2;5 reg [23:0] tone;6 always @(posedge clk) tone <= tone+1;7 reg [14:0] counter;8 always @(posedge clk) if(counter==0) counter <= (tone[23] ? clkdivider-1 : clkdivider/2-1); else counter <= counter-1;9 reg speaker;10 always @(posedge clk) if(coun...Read more

evaluation - Shunting yard (Reverse Polish Notation/Postfix) operator precedence

I'm trying to figure out what the precedence is for the different operators when implementing the shuting yard algorithm.My abstract syntax tree is in infix and I'm evaluating using the shuting yard algorithm. This works just fine for the arithmetic operators. The issue I'm facing is that I don't know what precedence all the other operators has.From https://en.wikipedia.org/wiki/Shunting-yard_algorithm I can see that the following is true for these operators. The number is the precedence.^ 4 * 3 / 3+ 2− 2But I cannot seem to find an...Read more

operators - A more high-level explanation of Forth

PreambleForth, through the few manuals I've read, is often defined in extremely low-level terms, typically in assembly. Defining Forth in this way is extremely counter-intuitive for understanding implementations, and truly only shines for writing assembly-based or other low-level-language based ports of Forth to varying systems/architectures.This can be seen in the famous JonesForth, where he implements words that are not necessary to implement in assembly for speed, and which blur the line between where the assembly ends and the Forth begins.S...Read more

Assigning null value using arithmetic operator is not working. -Uima Ruta

I tried to Assign a null value for a String using arithmetic operator but It's not working. It's assigning the previous value.Sample Input:Hi, How are you? 1I'm Fine 2Sample Script:PACKAGE uima.ruta.example;DECLARE Page(STRING Id);DECLARE PageId;"Hi, How are you\\? 1"->Page;"I'm Fine 2"->Page;"1"{->PageId}; BLOCK(foreach)Page{} { STRING pageid="null"; PageId{->MATCHEDTEXT(pageid),LOG("PageId"+pageid)}; Page{->Page.Id=pageid}; }...Read more

How does score multiplier operator in Watson Discovery service work?

I have a set of JSON documents uploaded to my WDS instance. I want to understand the importance of the score multiplier operator(^). The document just says,"Increases the score value of the search term". I have tried a simple query on one field, it multiplies the score by the number specified.If I specify two fields & I want Watson Discovery to know which of the two fields is more important for the search, is score multiplier applicable in this case? With two fields & a score multiplier applied to one, I could not identify the differenc...Read more

Google's search operator AND

I am trying to figure out how exactly google's search operator AND works for an application that I am currently building.I found this article:https://supple.com.au/tools/google-advanced-search-operators/that says that google uses AND operator as a default operator when searchinghowever I am trying some examples and this doesn't seem to be the whole storyFor example, when I search for:Google search term: perth tourism sea surfingit gives me more search results than:Google search term: perth tourism seaHow is that possible, I would expect that AN...Read more

user defined functions - Why don't new operator definitions persist in the Perl 6 REPL?

I was having issues experimenting with defining operators on the Perl 6 REPL, and noticed that they do work, but only when used on the same line as they are defined. Why is this the case?> sub postfix:<!>(Int $x where { $x >= 0 }) { [*] 1..$x }; 6!;720> 6!;===SORRY!=== Error while compiling:Negation metaoperator not followed by valid infix------> 6!⏏; expecting any of: infix infix stopper...Read more

operators - SYMBOL-VALUE of +,/ and *

Consider the following code snippet:[1]> (symbol-value '+)NIL[2]> +(SYMBOL-VALUE '+)[3]> (symbol-value '/)((SYMBOL-VALUE '+))[4]> (symbol-value '+)(SYMBOL-VALUE '/)[5]> *(SYMBOL-VALUE '/)So, according to my observation, symbol-value of + is the last input to the REPL. symbol-value of / is the last output of the REPL in parenthesis.symbol-value of * is the last output of the REPL as it is.What is the reason for this?There seems to be little reason for checking what was your last input, last output, as it is already on the REPL.So...Read more

Scheme: why this result when redefining a predefined operator?

I received an unexpected result when redefining the + operator in a scheme program using guile. I should point out that this occurred while experimenting to try to understand the language; there's no attempt here to write a useful program.Here's the code:(define (f a b) 4)(define (show) (display (+ 2 2)) (display ",") (display (f 2 2)) (newline))(show); guile & mit-scheme: "4,4"(define (+ a b) 5)(define (f a b) 5)(show); mit-scheme: "5,5"; guile: "4,5" - this "4" is the unexpected result(define (show) (display (+ 2 2)) (display ",") (disp...Read more

operators - J: Tacit adverb of Newton's method

I've found in 'addons/math/misc/brent.ijs' implementation of Brent's method as an adverb. I would like to build a Newton's method as an adverb too but it's much harder than building tacit verbs. Here is a explicit version of Newton's iteration: newton_i =: 1 : '] - u % u d.1'With such usage: 2&o. newton_i^:_ (1) NB. (-: 1p1) must be found1.5708 2 o. 1.5708 NB. after substitution we get almost 0_3.67321e_6And of course, for convenience: newton =: 1 : 'u newton_i^:_'What's a tacit equivalent?...Read more

Where can one find a list of all the operators in J

I am trying to learn J and one huge problem I'm running into is I don't know what all the predefined operators are or where to find them. It took me way too long to figure out the | is both the remainder function(when it dyadic) but when its used monadic it gets absolute value or magnitude. Does any one know where a list of all the operators that J defines by default could be found?...Read more

bit manipulation - Is Modulus more efficient than And operator for finding halfs

I started playing with bitwise operators today I noticed that the & operator could be used to find if something is even or not.100 & 1;//Gives 0101 & 1;//Gives 1Zeros for even and ones for odds.So, I am currently wondering which is a more efficient method of finding if something is even:A)if (n & 1 == 0) isEven = true;orB)if(n % 2 == 0) isEven = true;Also, is there a more efficient way to find if something is even?P.S. There is no reason that I need for an efficient way of finding if something is an even number, I am just genuin...Read more