Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binary representations of ints

Status
Not open for further replies.

Arioch

Programmer
Apr 12, 2000
3
US
How are variables of type int represented in binary by Java?  Specifically, where is the bit for the positive/negative sign and do the shift operators (<<,>>,>>>) move it?  Any help or pointer to documentation would be appreciated.  Thanks.
 
Dear Arioch,<br><br>You should find that the bitwise representation of the native types are equal to that of their C++ counterparts.<br><br>Also since the native types are all signed, if you should need to do 32 bit unsigned operations you might look into the BigInteger class.<br><br>For documentation try <A HREF=" TARGET="_new"> this helps<br>-pete<br>
 
hi,<br><br>In Java the bit for representing the sign is the Most Significant Bit (MSB).<br><br>With regard to the operators &gt;&gt; &lt;&lt; and &gt;&gt;&gt;<br><br>&gt;&gt;&nbsp;&nbsp;:- signed right shift oprerator<br><br>&nbsp;In this case the MSB is replaced with the bit that was originally the MSB. So for neagtive numbers when this operator is applied it retains the negative sign<br><br>&lt;&lt;&nbsp;&nbsp;:- signed left shift operator<br>The bits that are added to the LSB side are 0's <br><br>&gt;&gt;&gt; :- unsigned right shift opertaor.<br><br>The bits that are added to the MSB side are 0's<br><br>Regards<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top