pelican
pelican

Reputation: 79

understanding a bitwise calculation

I'm reading some code that performs bitwise operations on an int and stores them in an array. I've worked out the binary representation of each step and included this beside the code.

On another computer, the array buff is received as a message and displayed in hex as [42,56,da,1,0,0]

Why question is, how could you figure out what the original number was from the hex number. I get that 42 and 56 are the ASCII equivalent of 'B' and 'V'. But how do you get the number 423 from da '1' '0' '0'?

Thanks

Upvotes: 1

Views: 112

Answers (2)

pm100
pm100

Reputation: 50110

as glgl says it should be a7, you can see where that comes from

  buff[2] = reading&0xff; // 10100111            = 0xa7
  buff[3] = (reading>>8)&0xff; //00000001        = 1
  buff[4] = (reading>>16)&0xff; //00000000       = 0
  buff[5] = (reading>>24)&0xff; ////00000000     = 0

Upvotes: 3

glglgl
glglgl

Reputation: 91017

DA 01 00 00 is the little endian representation of 0x000001DA or just 0x1DA. This, in turn, is 256 + 13 * 16 + 10 = 474. Maybe you had this number and changed the program later and forgot to recompile?

Seen it from the other side, 423 is 0x1a7…

Upvotes: 5

Related Questions