Big Moose Saloon
 Search | Java FAQ | Recent Topics Register / Login

# Binary representation of -128

Naveed Hassan
Greenhorn

Joined: Feb 23, 2001
Posts: 17
Hi
We know the range of byte is -128 to +127.
I want to know how -128 is represented in binary system
Rana Thakur
Greenhorn

Joined: Feb 26, 2001
Posts: 26
-128 in a byte is represented as 1000 0000
Naveed Hassan
Greenhorn

Joined: Feb 23, 2001
Posts: 17
Well, then is there any idea for -0 (negative zero) in JAVA?
Wong KK
Ranch Hand

Joined: Jan 15, 2001
Posts: 52
there is no -0 in integer, for integer, -0 and +0 are the same.
There is -0.0 and +0.0 for float and double.
mansoor iqbal
Ranch Hand

Joined: Aug 14, 2000
Posts: 91
how do u get the binary of -128?
thanks
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
You start counting
0 = 0000 0000
+ 1 = 0000 0001
+ 127 = 0111 1111
- 128 = 1000 0000 (the left-most bit is the sign bit)
- 127 = 1000 0001 (you add 1 remember)
- 1 = 1111 1111
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089

Negative Numbers In Binary
Negative numbers in Binary are almost always displayed in "2's Complement" form.
For a negative number, invert all the bits of it's positive counterpart and add one. For Instance, in 16-bit decimal numbers:
1 = %0000 0000 0000 0001
Inverting the bits gives: %1111 1111 1111 1110
Adding 1 gives: %1111 1111 1111 1111 = -1

See : http://www.rz.uni-hohenheim.de/rz/sys/basics/csc102/ch2.html#bin_not
Velmurugan Periasamy
Ranch Hand

Joined: Nov 09, 2000
Posts: 95
Check out the programs on my site(In tips page).
http://www.geocities.com/velmurugan_p/
Best wishes.
------------------
Velmurugan Periasamy
Sun Certified Java Programmer
----------------------
Study notes for Sun Java Certification
http://www.geocities.com/velmurugan_p/

------------------------------------------------------------------------------------<BR>Velmurugan Periasamy<BR>Sun Certified Java Programmer for Java 2 Platform<BR>Sun Certified Web Component Developer for J2EE platform<BR>Sybase Certified EAServer Developer (similar to jCert level 3)<BR>------------------------------------------------------------------------------------<BR>Study notes for Sun Java Certification<BR><A HREF="http://www.geocities.com/velmurugan_p/" TARGET=_blank rel="nofollow">http://www.geocities.com/velmurugan_p/</A><BR>------------------------------------------------------------------------------------

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.

subject: Binary representation of -128