Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could someone explain how to get an integer from a four-byte sequence in a littl

ID: 3695048 • Letter: C

Question

Could someone explain how to get an integer from a four-byte sequence in a little endian ?

I understand this example,

The four-byte sequence 0x8A 0x8B 0x8C 0x57 in little-endian represents 1468828554 when interpretterd in 32-bit signed integer, as it was simply converting 578C8B8A into an integer, but I am a bit confused how we got the following...

T0x8B 0x6A 0x73 0x86 = -2039256437 as a 32-bit signed integer.

0xAB 0x3A 0x7C 0x96 = -1770243413 as a 32-bit signed integer.

0x22 0x88 0x8A 0x56 = 1451919394 as a 32-bit unsigned integer.

Explanation / Answer

In little endian bytes are represented in backwards.High byte value is at last.

in first one (0x8A 0x8B 0x8C 0x57) : 57 8C 8B 8A

sign bit is msb.in our case it is 0x8A whose binary representation is "0b10001010"(right most bit(msb))

the right most bit will serve as msb whic is our sign bit in our case it is 0 so +ve

for other cases here is my explanation:

1. 0x8B 0x6A 0x73 0x86 becomes 0x86736A8B (0x8B : '0b10001011') one so negative value.

  0x86736A8B -> 2255710859

    we have to take -(2^32-2039256437) which becomes -2039256437

2. 0xAB 0x3A 0x7C 0x96 becomes 0x967C3AAB (0xAB : '0b10101011') one so negative value.

   0x967C3AAB -> 2524723883

   we have to take -(2^32-2524723883) which becomes -1770243413

3. 0x22 0x88 0x8A 0x56 becomes 0x568A8822 (0x22 : '0b10110') zero so +ve value.

   0x568A8822 -> 1451919394