programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# right and left shifts for -ve numbers

Ranch Hand
Posts: 86
Hi,
I know this is a lame question but I had lot of doubts in it.
Can any body explain taking a -ve number convert it to binary form and show the << and >> shifts of it.
Thanks in bunches,

Ranch Hand
Posts: 59
Hi,
Check out this link....
http://www.hal-pc.org/%7Eclyndes/computer-arithmetic.html#COMPUTER-TWOS
The explanation given is very easy and will help you to clear you doubts.
HTPs
Mukti

Ranch Hand
Posts: 86
Hi mukthi,
Thankyou very much for the site . It is very explanative and very clear.Thankyou once again.

Ranch Hand
Posts: 86
Hi,
I got the site and understood fairly how to represent a negative number in binary form and left and right shift of postive numbers.
For example -13 binary is 1111 0011 and -13 >> 3 = 1111 1110.
I don't know how to interprete this as decimal number. Can anybody explain please?

Ranch Hand
Posts: 3141
Here's a link to some notes I have posted on Binary/Octal/Decimal/Hex converstions.
Hope they help.
------------------
Jane Griscti
Sun Certified Java 2 Programmer
[This message has been edited by Jane Griscti (edited February 12, 2001).]

Ranch Hand
Posts: 86
Hi Jane,
The site given by you is so good but I still have the doubt for -13>>3 1111 1110 which is equal to -2. Even in your sight there is anumber -16>>2 which is equal to -4. The only part I did not understood is the calc part to arrive at -2 from
1111 1110 or in the -16 example. Please try to explain.

Greenhorn
Posts: 16
The way to find out the value of that number is -i = (~i)+1 which means in your case:
~1111 1110 +1 = 0000 0001(bin)+1(bin) = 0000 0010(bin) = 2 (dec)
Therefore the value is -2
If you want to present -i = (~i)+1
16(dec) = 0001 0000
~16 = 1110 1111
~16+1 = 1111 0000