Possibly bug in Java 7 binary literals?

You're using a signed integer. Bit 32 (the "first" one from the left) is the sign bit. It being 1 means it is a negative number, and 0 means positive.

Two's complement is then performed to give the value of -1. Read about that here.

You're using a signed integer. Bit 32 (the "first" one from the left) is the sign bit. It being 1 means it is a negative number, and 0 means positive.

Two's complement is then performed to give the value of -1. Read about that here: tfinley.net/notes/cps104/twoscomp.html.

I don't think so, System.out. Println(0b011); still printing 3 – Eng. Fouad Jan 8 at 12:53 @Eng.

Fouad - as it should. The sign bit is waaaaay to the left :) – Perception Jan 8 at 12:55 Yes as I said, bit 32 .. 0b011 is actually the following in 32-bit architecture: 00000000000000000000000000000011 – Scott W Jan 8 at 12:55 In a signed integer 0b0.... will be positive, 0b1... will be negative. This is correct.

– brainzzy Jan 8 at 12:56 @Perception oh I see, thanks – Eng. Fouad Jan 8 at 12:56.

Indeed this is a signed int so is 0xffff == 0b11111111111111111111111111111111 == -1 and not a positiv number. See also Wikipedia Two's complement.

This is not a bug at all: since int is unsigned, all bits to 1 does mean -1. The leftmost bit of a signed integer, in two's complement, is the sign bit. What you see is therefore expected.

Then why System.out. Println(0b011); prints 3? – Eng.

Fouad Jan 8 at 12:54 Maybe bin10=dec2 and bin1=dec1 -> 1+2=3 // bin=binary & dec=decimal – rekire Jan 8 at 12:56.

Java uses 32 bit signed integers, and the max/min & overflow results you are seeing are valid. For more information see: en.wikipedia.org/wiki/Integer_(computer_...).

Java's int uses 2's complement signed integers. This means the leftmost bit indicates a negative number. So int x = 0b11111111111111111111111111111111; // ^--- this bit indicates the number is negative.

The fact that all of the other bits are also 1 means that the number is (decimal) -1. See the link for details.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send