• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Negative numbers shown in bits

 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay.. so here's an easy one for you. How can I represent -4 in bits. Any good rule of thumb would be great so its easy to remember how to do it later. I understand the positive 4. Thats easy. 0100
Thanks
-Dale
------------------
What's this H2SO4 doing in my fridge?? ( thud )
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read this:
http://www.javaranch.com/ubb/Forum33/HTML/001584.html
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dale
To find the negative value of a number you use the twos compliment:
1. take the positive number and flip all the bits (turn 1's into 0's and 0's into 1)
2. add 1 to the result
so for your example of -4
4 is
00000000 00000000 00000000 00000100
flip the bits
1111111 11111111 11111111 11111011
add 1
1111111 11111111 11111111 11111100
this is -4 in binary.

hope that helps
Dave
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
Dale

------------------
What's this H2SO4 doing in my fridge?? ( thud )
 
reply
    Bookmark Topic Watch Topic
  • New Topic