# Negative Numbers in Bits

L Sol

Greenhorn

Posts: 3

Richard Quist

Ranch Hand

Posts: 96

posted 12 years ago

Since negative numbers are represented in two's-complement form you need to

Flip all the bits add one restore the negative sign

original: 1111 1111 1111 1111 1111 1111 1111 1010

inverted: 0000 0000 0000 0000 0000 0000 0000 0101

add one: 0101

0001

----

0110 (which is 6 in base 10)

Restore negative sign: -6

Originally posted by L Sol:

How do you calculate the following number is equal to -6?

1111 1111 1111 1111 1111 1111 1111 1010

Thanks!

Since negative numbers are represented in two's-complement form you need to

original: 1111 1111 1111 1111 1111 1111 1111 1010

inverted: 0000 0000 0000 0000 0000 0000 0000 0101

add one: 0101

0001

----

0110 (which is 6 in base 10)

Restore negative sign: -6

Rich

SCJP 1.4

Serghei Jelauc

Ranch Hand

Posts: 128