Binary addition help!

boomdart

Senior member
Jan 10, 2004
825
0
0
Just to make sure I'm doing this right...

12 bit binary ones complement
101011001011
111111111011
-------------------
101011000110 = 10126 decimal

Correct?

If not please explain.
 

Legendary

Diamond Member
Jan 22, 2002
7,019
1
0
Windows calculator has the ability to do binary addition.
The answer it gives is: 1101011000110
Unfortunately it won't give me an explanation. Decimal wise it's 6854
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Most modern number systems use place-value as derived from the Babylonians' first use of it (although the Hindus first made use of zero, I believe), so every digit in a number starting from right to left indicates its placement starting from zero. With that in mind, you can use the following:

n = v * b ^ p

where 'v' is the value (1 or 0 in your case), 'b' is the base (2 in this case), and 'p' is the position of the digit from the right starting at zero. If you do this for each digit you can simply add them all together. Using your example you now have the following:

101011001011 = (1 * 2 ^ 0) + (1 * 2 ^ 1) + (0 * 2 ^ 2) + (1 * 2 ^ 3) ....

Make sense?
 

JetBlack69

Diamond Member
Sep 16, 2001
4,580
1
0
...101011001011 (-1332)
...111111111011 (-4)
--------------------
.1101011000110
..+........................1
..--------------------
...101011000111 (-1336)

The most significant bit is 1 for both numbers, meaning they are negative numbers. Since they are the same sign (negative) you can add them together. Since there is a final carry bit, you need to add 1 to the result to get what is shown above.

EDIT:hmmm...spaces didn't space the problem well. I'll use dots ... just ignore them.
 

RaynorWolfcastle

Diamond Member
Feb 8, 2001
8,968
16
81
Originally posted by: Descartes
Most modern number systems use place-value as derived from the Babylonians' first use of it (although the Hindus first made use of zero, I believe), so every digit in a number starting from right to left indicates its placement starting from zero. With that in mind, you can use the following:

n = v * b ^ p

where 'v' is the value (1 or 0 in your case), 'b' is the base (2 in this case), and 'p' is the position of the digit from the right starting at zero. If you do this for each digit you can simply add them all together. Using your example you now have the following:

101011001011 = (1 * 2 ^ 0) + (1 * 2 ^ 1) + (0 * 2 ^ 2) + (1 * 2 ^ 3) ....

Make sense?

What the hell does that have to do with the price of tea in China?!? :confused:

His question was about complementation so that you could use an adder to subtract in a finite length register. JetBlack's answer is correct, assuming the number on the bottom actually is a 1's complement instead of a 2's complement (as it usually is the case
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: RaynorWolfcastle
Originally posted by: Descartes
Most modern number systems use place-value as derived from the Babylonians' first use of it (although the Hindus first made use of zero, I believe), so every digit in a number starting from right to left indicates its placement starting from zero. With that in mind, you can use the following:

n = v * b ^ p

where 'v' is the value (1 or 0 in your case), 'b' is the base (2 in this case), and 'p' is the position of the digit from the right starting at zero. If you do this for each digit you can simply add them all together. Using your example you now have the following:

101011001011 = (1 * 2 ^ 0) + (1 * 2 ^ 1) + (0 * 2 ^ 2) + (1 * 2 ^ 3) ....

Make sense?

What the hell does that have to do with the price of tea in China?!? :confused:

His question was about complementation so that you could use an adder to subtract in a finite length register. JetBlack's answer is correct, assuming the number on the bottom actually is a 1's complement instead of a 2's complement (as it usually is the case

Simma down my fervent brutha.

I saw Legendary's response about the lack of explanation, so I jumped the gun.
 

RaynorWolfcastle

Diamond Member
Feb 8, 2001
8,968
16
81
Originally posted by: Descartes

Simma down my fervent brutha.

I saw Legendary's response about the lack of explanation, so I jumped the gun.

I'm not angry, I was just completely baffled by your answer to what seemed to be a simple question :eek:
:beer::D
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: RaynorWolfcastle
Originally posted by: Descartes

Simma down my fervent brutha.

I saw Legendary's response about the lack of explanation, so I jumped the gun.

I'm not angry, I was just completely baffled by your answer to what seemed to be a simple question :eek:
:beer::D

Yeah, I at least got a laugh out of myself :) I have the annoying habit of sometimes reading only 25% of a question before answering. :(

:beer:
 

boomdart

Senior member
Jan 10, 2004
825
0
0
Originally posted by: JetBlack69
...101011001011 (-1332)
...111111111011 (-4)
--------------------
.1101011000110
..+........................1
..--------------------
...101011000111 (-1336)

The most significant bit is 1 for both numbers, meaning they are negative numbers. Since they are the same sign (negative) you can add them together. Since there is a final carry bit, you need to add 1 to the result to get what is shown above.

EDIT:hmmm...spaces didn't space the problem well. I'll use dots ... just ignore them.

So how does 101011001011 = -1332? How do you convert the 0's and 1's to get the decimal number?

When I did 101011000110, i split it into groups of fours and determined it's numbers to be 10126...1010= 10, 1100= 12, 0110 = 6....Then I just attached them to each other... I guess that's the wrong way to do it, huh?
 

RaynorWolfcastle

Diamond Member
Feb 8, 2001
8,968
16
81
Ironically, it turns out that Descartes' post does have something to do with the price of tea in China. Read it over, it'll clear things up for you

Here's a quick rundown while I wait for my code to compile

if a number starts with a one, then you know it's a negative in a one's complement system. Namely, if you invert it, you get its magnitude.

so for example.

1010 is the equivalent to -0101 = -(2^2 + 2^0) = -5.
 

DOSfan

Senior member
Sep 19, 2003
522
0
0
Originally posted by: boomdart
Just to make sure I'm doing this right...

12 bit binary ones complement
101011001011
111111111011
-------------------
101011000110 = 10126 decimal

Correct?

If not please explain.

You are leaving off a one. In the "first" digit (The one on the left) you end up with 1 + 1 + 1 which equals 11 (Which would give you 1101011000110). Unfortunately, I am not certain how to account for it. (It has been too long since I did binary.... :( Sorry.)
 

JetBlack69

Diamond Member
Sep 16, 2001
4,580
1
0
Since it is in one's complement and the most significant bit (on the far left) is 1, I know it is a negative number. Since I want to convert it to decimal, I flip all of the bits (only because I know it's negative) So
101011001011 = -010100110100

Ok, now I can convert it to decimal.

0*2^11 +1*2^10 + 0*2^9 + 1*2^8 + 0*2^7 + 0*2^6 + 1*2^5 + 1*2^4 + 0*2^3 + 1*2^2 + 0*2^1 + 0*2^0

I can ignore anything multiplied with 0 to get:

1*2^10 + 1*2^8 + 1*2^5 + 1*2^4 + 1*2^2

and that equals 1336 and since it's negative a put the negative sign on it -1336
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: JetBlack69
Since it is in one's complement and the most significant bit (on the far left) is 1, I know it is a negative number. Since I want to convert it to decimal, I flip all of the bits (only because I know it's negative) So
101011001011 = -010100110100

Ok, now I can convert it to decimal.

0*2^11 +1*2^10 + 0*2^9 + 1*2^8 + 0*2^7 + 0*2^6 + 1*2^5 + 1*2^4 + 0*2^3 + 1*2^2 + 0*2^1 + 0*2^0

I can ignore anything multiplied with 0 to get:

1*2^10 + 1*2^8 + 1*2^5 + 1*2^4 + 1*2^2

and that equals 1336 and since it's negative a put the negative sign on it -1336

What's the going rate for Chinese tea?
 

JetBlack69

Diamond Member
Sep 16, 2001
4,580
1
0
Originally posted by: Descartes
Originally posted by: JetBlack69
Since it is in one's complement and the most significant bit (on the far left) is 1, I know it is a negative number. Since I want to convert it to decimal, I flip all of the bits (only because I know it's negative) So
101011001011 = -010100110100

Ok, now I can convert it to decimal.

0*2^11 +1*2^10 + 0*2^9 + 1*2^8 + 0*2^7 + 0*2^6 + 1*2^5 + 1*2^4 + 0*2^3 + 1*2^2 + 0*2^1 + 0*2^0

I can ignore anything multiplied with 0 to get:

1*2^10 + 1*2^8 + 1*2^5 + 1*2^4 + 1*2^2

and that equals 1336 and since it's negative a put the negative sign on it -1336

What's the going rate for Chinese tea?

42