O'Reilly logo

Java Illuminated, 4th Edition by Anderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

APPENDIX D

Representing Negative Integers

The industry standard method for representing negative integers is called two’s complement. Here is how it works:

For an integer represented using 16 bits, the leftmost bit is reserved for the sign bit. If the sign bit is 0, then the integer is positive; if the sign bit is 1, then the integer is negative.

For example, let’s consider two numbers, one positive and one negative.

0000 0101 0111 1001 is a positive integer, which we call a.

1111 1111 1101 1010 is a negative integer, which we will call b.

Using the methodology presented in Chapter 1 for converting a binary number to a decimal number, we can convert the binary number, a, to its decimal equivalent. Hence, the value of a is calculated as follows: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required