I'm trying to make the best out of the programming calculator in OS X, but I don't know these functions:
- byte flip
- word flip
- X<
- X>>Y
- RoL/RoR (are these just sll/srl?)
Also is it possible to perform a two's complement on a narrower range i.e. 16 bits instead of 64 bits?
Best Answer
Flipping
Byte flip and word flip will swap bytes or words. Technically it works like this:
Let's say we have a two byte value (hexadecimal): 0x3344
The number consists of two bytes, the lower one is 0x44, and the higher one is 0x33, so let's put them into two imaginary cells of one byte size:
Now, flip the cells:
Therefore byte flipped value will be 0x4433
Same way with words, considering word consists of two bytes. Let's assume we have a two-word value: 0x12345678
Split them into two imaginary cells, now containing one word (2 bytes) each:
Now, flip the cells:
Therefore word flipped value will be 0x56781234
Shifting
Shifting shifts values bitwise. What does it mean?
Let's take a very simple decimal number: 5 Then, let's convert it to its binary representation: 101 Then, let's shift it left by 1:
We basically moved the whole binary sequence left one position and filled the empty space with zero.
Now do the same, but with shifting right:
our number is 10 now. The lower 1 is lost by shifting right. The zero on the left is just for display and has no value. // Technically there's a CPU flag which indicates that the bit was lost, but it is not relevant to the calculator.
Rotating
Rotating works absolutely same as shifting with one exception: bits are never lost. So, we take the same decimal value 5 and its binary representation 101. Then we rotate it right within a byte:
As you can see, the [1] which was lost on the shifting right was carried on the beginning of our byte.
Same with shifting left, let's perform series of rotations by 1 bit left until we carry one bit: