programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Jeanne Boyarsky
• Tim Cooke
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Carey Brown
• Frits Walraven
Bartenders:
• Piet Souris
• Himai Minh

# Binary representation of -128

Greenhorn
Posts: 17
• Number of slices to send:
Optional 'thank-you' note:
Hi
We know the range of byte is -128 to +127.
I want to know how -128 is represented in binary system

Greenhorn
Posts: 26
• Number of slices to send:
Optional 'thank-you' note:
-128 in a byte is represented as 1000 0000

Naveed Hassan
Greenhorn
Posts: 17
• Number of slices to send:
Optional 'thank-you' note:
Well, then is there any idea for -0 (negative zero) in JAVA?

Ranch Hand
Posts: 52
• Number of slices to send:
Optional 'thank-you' note:
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.

Ranch Hand
Posts: 91
• Number of slices to send:
Optional 'thank-you' note:
how do u get the binary of -128?
thanks

tumbleweed
Posts: 5089
• Number of slices to send:
Optional 'thank-you' note:
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
Posts: 5089
• Number of slices to send:
Optional 'thank-you' note:

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

Ranch Hand
Posts: 95
• Number of slices to send:
Optional 'thank-you' note:
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/

 You can thank my dental hygienist for my untimely aliveness. So tiny: Free, earth friendly heat - from the CodeRanch trailboss https://www.kickstarter.com/projects/paulwheaton/free-heat