This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

right and left shifts for -ve numbers

 
madhuri vl
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
madhuri.
 
Mukti Bajaj
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
madhuri vl
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mukthi,
Thankyou very much for the site . It is very explanative and very clear.Thankyou once again.
Madhuri.
 
madhuri vl
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Thanks in advance,
Madhuri.
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Madhuri,
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).]
 
madhuri vl
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Madhuri.
 
Maja Grabovac
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
madhuri vl
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I got solution for this from Marcusgreen tutorials where he has an applet giving the result. Anyway thankyou and can u please show one example for a -ve num with >>>. like -2 >>> 2.
Thankyou in advance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic