0

hi could anyone tell me how to get bit pattern of a negetive number.
For example bit pattern of -1357 is:
11111111111111111111101010110011
and bit pattern of 1357 is:
00000000000000000000010101001101

but how????

4
Contributors
7
Replies
9
Views
7 Years
Discussion Span
Last Post by stultuske
Featured Replies
1

you flip the bits and add 1. its also known as twos complement.

TJ

0

you flip the bits and add 1. its also known as twos complement.

TJ

So if we have get a pattern of a negetive number, first we would have to convert the positive and then flip bits or is there any other way

0

i would just convert to positive. its as easy as multiplying by -1 in your code or just dropping the - sign by hand.

TJ

0

i would just convert to positive. its as easy as multiplying by -1 in your code or just dropping the - sign by hand.

TJ

Thanks man, but one last thing if u could tell me that why there is 1 at the end of both numbers(( we have to flip the bit))??

0

the 1 is there because you have to add one when doing twos complement, so you do it like you would elementary addition and carry the one whenever you get 2 as the total. however the first digit is 0 so you can add 1 to it without changing any of the other bits.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.