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????

## Recommended Answers

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

TJ

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

TJ

## All 7 Replies

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

TJ

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

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

TJ

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))??

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.

10

10

yah?? ow key.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.