This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.

x=1; x << 29 yields 536870912, whose binary representation is all zeroes except '1' in the 30th higher order bit. x << 30 yields 1073741824, whose binary representation is all zeroes except '1' in the 31th higher order bit. What happens when x << 31 ?? Can anyone explain please in detail with the regd to the bits in binary form ?? Thanx, Vijay

Integers in Java are signed. So the Most Significant Bit is the sign bit. Here, I am just showing the Binary representation for the integers considered. U cud also get it with the static function of Integer class.... Integer.toBinaryString(int i); For example, 0000 0000 0000 0000 0000 0000 0000 0010 = 2

1111 1111 1111 1111 1111 1111 1111 1110 = -2 -2 is here represented in two's complement form. To get to the exact representation of any number in 2's complement notation u cud do it this way, 0000 0000 0000 0000 0000 0000 0000 0010 = 2 Invert it, 1111 1111 1111 1111 1111 1111 1111 1101 Then add 1 to it, +1 1111 1111 1111 1111 1111 1111 1111 1110 = -2

Here,in ur example,initially,i is 1 0000 0000 0000 0000 0000 0000 0000 0001 = 1 then i<<29 is 0010 0000 0000 0000 0000 0000 0000 0000 which is Big Positive number. i<<31 moves i to the Most significant bit 1000 0000 0000 0000 0000 0000 0000 0000 which is the representation for -2147483648

Hope this helps! [ February 18, 2002: Message edited by: Jennifer Wallace ]

vijay gardiner
Greenhorn

Joined: Jan 26, 2002
Posts: 14

posted

0

thanx! that helps! Vijay

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com