6

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?

  • 2
    You can hover over the calculator keys to see a short description of what they do. Also, watch the binary values to see a bit better what's actually going on. – Asmus Dec 21 '14 at 23:47
  • In order to limit the range of 2's or 1's compliment, simply AND it with FFFF for 16 bits, FF for 8, etc. MAKE SURE you keep it in hex format while doing those operations though, otherwise it messes it up. – MarcusJ Aug 25 '16 at 4:11
  • There is also an alternative to stock calculator: bitcalc.abeghyan.com – Pablo Nov 5 '18 at 12:44
6

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:

[33][44]

Now, flip the cells:

[44][33]

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:

[1234][5678]

Now, flip the cells:

[5678][1234]

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:

[101] << [1010]

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:

[101] >> [010]

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:

[00000101] ROR [10000010]

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:

[00000101] ROL [00001010]
[00001010] ROL [00010100]
[00010100] ROL [00101000]
[00101000] ROL [01010000]
[01010000] ROL [10100000]
[10100000] ROL [01000001]
  • This doesn't answer the question wrt to how to accomplish this with the Calculator app itself. Nor does it address the 2's compliment question. The question still begs an answer like 'press x button then y button, etc.' Either the question is not formulated correctly or this, the currently accepted answer, doesn't address the question directly. – Rondo Jul 11 '16 at 3:36
  • Word flipping is another way of saying endian swapping btw. – MarcusJ Aug 25 '16 at 4:08
  • @MarcusJ or rather the opposite. Flipping is a broad, generic term, endian swapping is narrowed down to the particular application. – Rilakkuma Aug 27 '16 at 10:12
1
  • byte flip / word flip - not sure about these
  • X<<Y / X>>Y - bitshift X to the left/right Y times
  • RoL / RoR - Rotate left/right, similar to bitshifing, except the bits wrap around in a circular fashion

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .