Question

This more of a hw question but I cannot figure this one out. I thought it would be 214 but because of the first bit on the left, I am not so sure.

Was it helpful?

Solution

As it's a 2's complement number, the first bit being one means that it's a negative number.

The value is 214 - 256 = -42.

It can also be calculated as -(~214 + 1) = -(41 + 1) = -42.

Binary that would be -(~11010110 + 1) = -(00101001 + 1) = -00101010.

OTHER TIPS

the translation is simple:

1: substract 1 from x

11010110-00000001=11010101

2: invert it

00101010

3: calculate binary to dec (but ignore first bit)

2+8+32 = 42

4: remember the first bit of original value ( == 1) if 1 => invert it => -42

You can tell it's a negative number since there's a 1 in the leftmost bit position. One way you can get the magnitude is invert all the bits and then add 1.

11010110
00101001 <= inverted
00101010 <= +1

This result is decimal 42, so the original value is representing -42.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top