Jump to content

Negative decimal to binary

- - - - -

  • Please log in to reply
2 replies to this topic

#1
vaironl

vaironl

    Programmer

  • Members
  • PipPipPipPip
  • 117 posts
Hello forum, Vaironl here.
I have a really simple question ( Which I myself don't understand, why I can't get it).

I have a test tomorrow which is about binary, hexadecimals and decimals. The decimals to hexadecimal and binary part is not complicated for me anymore.
But the negative decimal which I just figured I was going to be quizzed on, is pretty annoying for me.

Lets say a number like -48.

The way I do it:

1st- 48 in binary: 00110000

2nd- Flip the bits:11001111
+00000001
3rd add 1- How the heck? I know it cannot be two so how can I add one

#2
Sysop_fb

Sysop_fb

    Programmer

  • Members
  • PipPipPipPip
  • 160 posts
  • Location:Missouri
How to Add Binary Numbers: 7 steps (with pictures)

That should answer your question related to adding binary numbers.

If your test is covering how to do a twos compliment I would hope they would of already taught adding binary numbers though but it's easy to forget those types of things when you never do it very often.

twos compliment is ingenious though when you get the hang of it..

48 is 00110000
so flip the bits to 11001111 and add 1

   11001111
+  00000001
------------------
   11010000

so 11010000 is -48 which means that

   11010000
+  00110000   <--- 48
------------------
1  00000000
and the one falls off the bit bucket and flips the carry flag but you're left with 0

"The best optimizer is between your ears" - Michael Abrash
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.

#3
vaironl

vaironl

    Programmer

  • Members
  • PipPipPipPip
  • 117 posts

Sysop_fb said:

How to Add Binary Numbers: 7 steps (with pictures)

That should answer your question related to adding binary numbers.

If your test is covering how to do a twos compliment I would hope they would of already taught adding binary numbers though but it's easy to forget those types of things when you never do it very often.

twos compliment is ingenious though when you get the hang of it..


48 is 00110000

so flip the bits to 11001111 and add 1


   11001111

+  00000001

------------------

   11010000


so 11010000 is -48 which means that


   11010000

+  00110000   <--- 48

------------------

1  00000000

and the one falls off the bit bucket and flips the carry flag but you're left with 0

Thanks, I can't believe I never noticed the part I had problems with was adding it.
To check my work lets see if I can do - 57

1-Binary 57 = 00111001
2-Flip the bits = 11000110
3-add one +000000001
4-= 11000111




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users