• Post Reply Bookmark Topic Watch Topic
  • New Topic
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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Binary representation of -128

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-128 in a byte is represented as 1000 0000
 
Naveed Hassan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, then is there any idea for -0 (negative zero) in JAVA?
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do u get the binary of -128?
thanks
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!