This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Negative Numbers in Bits

 
L Sol
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you calculate the following number is equal to -6?
1111 1111 1111 1111 1111 1111 1111 1010
Thanks!
 
Richard Quist
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by L Sol:
How do you calculate the following number is equal to -6?
1111 1111 1111 1111 1111 1111 1111 1010
Thanks!

Since negative numbers are represented in two's-complement form you need to
  • Flip all the bits
  • add one
  • restore the negative sign

  • original: 1111 1111 1111 1111 1111 1111 1111 1010
    inverted: 0000 0000 0000 0000 0000 0000 0000 0101
    add one: 0101
    0001
    ----
    0110 (which is 6 in base 10)
    Restore negative sign: -6
     
    Serghei Jelauc
    Ranch Hand
    Posts: 128
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Let say we have 1111 1101
    Change all 1 and 0 vice versa: 0000 0010
    0000 0010 = 2.
    After it add 1: now have 3
    and add "-" sign: -3
    That's all.
    Hope it halps
     
    Corey McGlone
    Ranch Hand
    Posts: 3271
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you want more information regarding 2's complement, do a search over this forum - you'll find tons of good information.
    Corey
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic