hexa

class BitShift {

public static void main(String [] args) {

int x = 0x80000000;

System.out.println("Before shift x equals " + x);

x = x << 1;

System.out.println("After shift x equals " + x);

}

}

%java BitShift

Before shift x equals -2147483648

After shift x equals 0

now 0x80000000 how it is equal to -2147483648

1000 0000 0000 0000 0000 0000 0000 0000 <-this 1 one is the sign, isnt int is 32 bit so -2^31 to 2^31�1.....so 1 is value to 2power 32 how come 32 isnt 31......32 with sign so in this exampe the 1 is sign no value

public static void main(String [] args) {

int x = 0x80000000;

System.out.println("Before shift x equals " + x);

x = x << 1;

System.out.println("After shift x equals " + x);

}

}

%java BitShift

Before shift x equals -2147483648

After shift x equals 0

now 0x80000000 how it is equal to -2147483648

1000 0000 0000 0000 0000 0000 0000 0000 <-this 1 one is the sign, isnt int is 32 bit so -2^31 to 2^31�1.....so 1 is value to 2power 32 how come 32 isnt 31......32 with sign so in this exampe the 1 is sign no value

> Before shift x equals -2147483648

In binary, it looks like this:

10000000 00000000 00000000 00000000

It's in two's complement format, so the leftmost bit is the sign. Remember that it indicates a negative (1-neg, 0-pos). Then, flip the bits and add one.

flip:

01111111 11111111 11111111 11111111

add one:

10000000 00000000 00000000 00000000

Read this like a regular binary number (2147483648), but remember that it was negative. That's why 0x80000000 is -2147483648 in decimal.

> After shift x equals 0

When you shift the bits left, it fills with zeros. High bits drop off the left side, never to return. So, when you shift this left by one...

10000000 00000000 00000000 00000000

...you get...

00000000 00000000 00000000 00000000

The high order bit dives into the bit bucket, and we're left with zero.

Hope this helps.

In binary, it looks like this:

10000000 00000000 00000000 00000000

It's in two's complement format, so the leftmost bit is the sign. Remember that it indicates a negative (1-neg, 0-pos). Then, flip the bits and add one.

flip:

01111111 11111111 11111111 11111111

add one:

10000000 00000000 00000000 00000000

Read this like a regular binary number (2147483648), but remember that it was negative. That's why 0x80000000 is -2147483648 in decimal.

> After shift x equals 0

When you shift the bits left, it fills with zeros. High bits drop off the left side, never to return. So, when you shift this left by one...

10000000 00000000 00000000 00000000

...you get...

00000000 00000000 00000000 00000000

The high order bit dives into the bit bucket, and we're left with zero.

Hope this helps.

Those are the largest trousers in the world! Especially when next to this ad:

ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter

https://coderanch.com/t/690611/ScroogeXHTML-RTF-HTML-XHTML-converter
This thread has been viewed 379 times.

All times above are in ranch (not your local) time.

The current ranch time is

Feb 19, 2018 20:18:02.

The current ranch time is

Feb 19, 2018 20:18:02.