Originally posted by kittu anu:
Hi all,
I am confused !!
can some one give an example like how to find the binary number for negative numbers.
i know this tech. to get the binary number for -ve values.Please correct me b'coz for some numbers i am getting diff. values.
lets take -192
step1:
we should take 192 and minus 1 i,e 191
step2:
get the binary form for 191 i,e 10111111
step3:and then change 0's to 1 and 1's to 0's
i,e 01000000(which is the binary value of -192)
I am going in the right way.please let me know.
Well, how about we go from negative to positive and then back! Let's take an easy number to work with: -1. The binary representation for -1 is simple (I'll use just eight bits instead of the 32 in an int): 11111111. Now, to get the positive version, we flip all the bits, so our binary number is now 00000000. Then, we add 1, so we get 00000001. In decimal, this is a positive 1.
Now, to take a positive to a negative, we just reverse the process - so subtract 1 from our binary 00000001 and we get 00000000, then flip the bits and we get 11111111, which is the binary representation of -1 in decimal. Just repeat the process for any number.
Easy, isn't it! The best way to check your work is to use a calculator that works in binary and decimal - I always use the calculator that comes with Windows and turn on the scientific view to use the different bases.