aspose file tools*
The moose likes Mock Exam Errata and the fly likes right and left shifts for -ve numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "right and left shifts for -ve numbers" Watch "right and left shifts for -ve numbers" New topic
Author

right and left shifts for -ve numbers

madhuri vl
Ranch Hand

Joined: Jan 17, 2001
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,
madhuri.


madhuri.
Mukti Bajaj
Ranch Hand

Joined: Dec 11, 2000
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
madhuri vl
Ranch Hand

Joined: Jan 17, 2001
Posts: 86
Hi mukthi,
Thankyou very much for the site . It is very explanative and very clear.Thankyou once again.
Madhuri.
madhuri vl
Ranch Hand

Joined: Jan 17, 2001
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?
Thanks in advance,
Madhuri.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
madhuri vl
Ranch Hand

Joined: Jan 17, 2001
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.
Madhuri.
Maja Grabovac
Greenhorn

Joined: Feb 27, 2001
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
madhuri vl
Ranch Hand

Joined: Jan 17, 2001
Posts: 86
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: right and left shifts for -ve numbers