Avinash Haridasu wrote:Can any one tell me
how do we decide whether a number is negative or positive just by looking at the binary representation
0 0 0 0 0 0 0 1 = 1
1 1 1 1 1 1 1 1 = −1
Campbell Ritchie wrote:but you ought to remember that only applies to two's complement numbers. The char for example is unsigned and behaves differently.
No, Jesper actually means 65535, assuming that is the bit pattern for a char. That is equivalent to the Unicode character for ffff, and you can find what that is here.
Stephan van Hulst wrote:Did you mean -1?
Campbell Ritchie wrote:Look in the Java Language Specification and you find that the number of bits shifted is calculated % i where i is the number of bits in the datatype. So for everything except a long, shift 37 and shift 5 have the same effect.
i >> 5 is equivalent to i / 32
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your databasehttps://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database