Signed addition
Electronics Forum Index Electronics
Circuits, theory, electrons and discussions.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web ElectronicsHelp.net
Signed addition

 
Post new topic   Reply to topic    Electronics Forum Index -> Design
Author Message
Juha Turunen
Guest





Posted: Tue Feb 08, 2005 7:13 pm    Post subject: Signed addition Reply with quote

Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

So what I planned was to make a circuit that first converts the
numbers to 1's complement if the sign bit is 1 with XOR gates and
then adding them together. The carry out of the last adder must be
connected to the carry in of the first adder, right? The result is
converted back to the original number format.

Will this work?

--
Juha Turunen (turunen(at)iki.fi) elpuri@IRC | The problem with the global
Torikatu 5A4, 53900 Lappeenranta, Finland | village are all the global
GSM: 040-7092525, http://iki.fi/turunen/ | village idiots.

Back to top
Tim Wescott
Guest





Posted: Tue Feb 08, 2005 9:18 pm    Post subject: Re: Signed addition Reply with quote

Juha Turunen wrote:
Quote:
Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

Ah! A statement that it's homework! Good! This means that I won't
give you hell, or ignore the post. Unfortunately it also means I'll
only ask questions -- but hopefully they'll be helpful questions.

Such a number format would make sense in some cases - as soon as you get
off the beaten path of microprocessors and into FPGA design anything can
happen.
Quote:

So what I planned was to make a circuit that first converts the
numbers to 1's complement if the sign bit is 1 with XOR gates and
then adding them together.

Is that the least-complicated way to do it (this is a true question -- I
don't know)? When you add things by hand you use a sign + magnitude
notation -- do you convert to 9's complement, add, wrap the carry, then
convert back to sign + magnitude, or is there something else you do?

Check out the 74181, by the way.

Quote:
The carry out of the last adder must be
connected to the carry in of the first adder, right?

This is a 1's complement thing, isn't it? Is your last carry ever
affected by your first carry? If so, what happens to your circuit?

Quote:
The result is
converted back to the original number format.

Will this work?

If you came up with it I think you already know the answer to that.


--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com
Back to top
Fred Bloggs
Guest





Posted: Tue Feb 08, 2005 9:22 pm    Post subject: Re: Signed addition Reply with quote

Juha Turunen wrote:
Quote:
Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

It makes sense in terms of testing your knowledge of arithmetic
operations on various forms of binary number representations, and in
your case it looks like you fail. Go back and review the material until
you understand it, then answer the question yourself.

Back to top
Spehro Pefhany
Guest





Posted: Tue Feb 08, 2005 9:42 pm    Post subject: Re: Signed addition Reply with quote

On 8 Feb 2005 13:13:01 GMT, the renowned Juha Turunen
<jtt7665@maa2.cc.lut.fi> wrote:

Quote:
Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

It might. For example, if the number was to be displayed or printed or
transmitted as human-readable ASCII, that would be a good format.
Two's complement would require work to display a negative number
correctly.

Quote:
So what I planned was to make a circuit that first converts the
numbers to 1's complement if the sign bit is 1 with XOR gates and
then adding them together. The carry out of the last adder must be
connected to the carry in of the first adder, right? The result is
converted back to the original number format.

Will this work?

How about you do a mental/pen and paper simulation with test cases
that are in all 4 quadrants and tell us whether it works.


Best regards,
Spehro Pefhany
--
"it's the network..." "The Journey is the reward"
speff@interlog.com Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog Info for designers: http://www.speff.com
Back to top
Juha Turunen
Guest





Posted: Wed Feb 09, 2005 1:57 am    Post subject: Re: Signed addition Reply with quote

Fred Bloggs wrote:
Quote:


Juha Turunen wrote:
Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

It makes sense in terms of testing your knowledge of arithmetic
operations on various forms of binary number representations, and in
your case it looks like you fail. Go back and review the material until
you understand it, then answer the question yourself.

Thanks for your answer, though I found the other ones much more
educational. I know a lot of people try to get other on USENET to do their
homework. That's why I came up with a solution and thought about asking
other people, if I should even bother trying it out.

Next time someone asks something maybe you could try to be more
constructive like the other ones that replied or maybe not reply
at all instead of wasting two minutes of your life writing a
semi-polite fuck you.

--
Juha Turunen (turunen(at)iki.fi) elpuri@IRC | The problem with the global
Torikatu 5A4, 53900 Lappeenranta, Finland | village are all the global
GSM: 040-7092525, http://iki.fi/turunen/ | village idiots.
Back to top
Tim Wescott
Guest





Posted: Wed Feb 09, 2005 3:19 am    Post subject: Re: Signed addition Reply with quote

Juha Turunen wrote:
Quote:
Fred Bloggs wrote:


Juha Turunen wrote:

Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

It makes sense in terms of testing your knowledge of arithmetic
operations on various forms of binary number representations, and in
your case it looks like you fail. Go back and review the material until
you understand it, then answer the question yourself.


Thanks for your answer, though I found the other ones much more
educational. I know a lot of people try to get other on USENET to do their
homework. That's why I came up with a solution and thought about asking
other people, if I should even bother trying it out.

Next time someone asks something maybe you could try to be more
constructive like the other ones that replied or maybe not reply
at all instead of wasting two minutes of your life writing a
semi-polite fuck you.

Oh, don't mind Fred -- he's one of our resident cranks. I think he must

flip a coin each time or something, because he's helpful about 1/2 the time.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com
Back to top
Andrew Holme
Guest





Posted: Wed Feb 09, 2005 3:31 am    Post subject: Re: Signed addition Reply with quote

Juha Turunen wrote:
Quote:
Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

So what I planned was to make a circuit that first converts the
numbers to 1's complement if the sign bit is 1 with XOR gates and
then adding them together. The carry out of the last adder must be
connected to the carry in of the first adder, right? The result is
converted back to the original number format.

Will this work?

If the magnitude was 8-bit, the one's complement of x would be 255-x. If
you write equations for the output of your circuit in at least three of the
four quadrants, you'll see the answer.
Back to top
Fred Bloggs
Guest





Posted: Wed Feb 09, 2005 6:59 am    Post subject: Re: Signed addition Reply with quote

Juha Turunen wrote:
Quote:
Fred Bloggs wrote:


Juha Turunen wrote:

Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

It makes sense in terms of testing your knowledge of arithmetic
operations on various forms of binary number representations, and in
your case it looks like you fail. Go back and review the material until
you understand it, then answer the question yourself.


Thanks for your answer, though I found the other ones much more
educational. I know a lot of people try to get other on USENET to do their
homework. That's why I came up with a solution and thought about asking
other people, if I should even bother trying it out.

Is that what you call a "solution"- a little piss ant vague verbal
description?

Quote:

Next time someone asks something maybe you could try to be more
constructive like the other ones that replied or maybe not reply
at all instead of wasting two minutes of your life writing a
semi-polite fuck you.

Ok- here's a not-so-polite f_ck you. Now for the not-so-constructive
criticism: it is clear that you are little poof punk bs artist, you are
a slouch and a shirker, as well as an uneducable low life enrolled in
the wrong course of study.

>
Back to top
Rich Grise
Guest





Posted: Wed Feb 09, 2005 8:38 am    Post subject: Re: Signed addition Reply with quote

On Tue, 08 Feb 2005 19:57:49 +0000, Juha Turunen wrote:

Quote:
Fred Bloggs wrote:


Juha Turunen wrote:
Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

It makes sense in terms of testing your knowledge of arithmetic
operations on various forms of binary number representations, and in
your case it looks like you fail. Go back and review the material until
you understand it, then answer the question yourself.

Thanks for your answer, though I found the other ones much more
educational. I know a lot of people try to get other on USENET to do their
homework. That's why I came up with a solution and thought about asking
other people, if I should even bother trying it out.

Next time someone asks something maybe you could try to be more
constructive like the other ones that replied or maybe not reply
at all instead of wasting two minutes of your life writing a
semi-polite fuck you.

No worries, new friend. That's just Fred. ;-)

And now, you've got me thinking about the problem. The format is called
sign-magnitude, by the way - maybe I better go read some more replies
before I repeat (or munge) what somebody else has already said...

Cheers!
Rich
Back to top
Pig Bladder
Guest





Posted: Wed Feb 09, 2005 8:40 am    Post subject: Re: Signed addition Reply with quote

On Wed, 09 Feb 2005 00:59:18 +0000, Fred Bloggs wrote:
Quote:
Ok- here's a not-so-polite f_ck you.

Right back at ya!
--
The Pig Bladder From Uranus, Still Waiting for
Some Hot Babe to Ask What My Favorite Planet Is.
Back to top
Rich Grise
Guest





Posted: Wed Feb 09, 2005 8:41 am    Post subject: Re: Signed addition Reply with quote

On Tue, 08 Feb 2005 07:18:30 -0800, Tim Wescott wrote:
Quote:
Juha Turunen wrote:
I need to add too signed binary numbers which are in a format such

Too signed? All of the numbers I've ever seen were either signed or not. ;-)

Quote:
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

Ah! A statement that it's homework! Good! This means that I won't
give you hell, or ignore the post. Unfortunately it also means I'll
only ask questions -- but hopefully they'll be helpful questions.

Such a number format would make sense in some cases - as soon as you get
off the beaten path of microprocessors and into FPGA design anything can
happen.

So what I planned was to make a circuit that first converts the
numbers to 1's complement if the sign bit is 1 with XOR gates and
then adding them together.

Is that the least-complicated way to do it (this is a true question -- I
don't know)? When you add things by hand you use a sign + magnitude
notation -- do you convert to 9's complement, add, wrap the carry, then
convert back to sign + magnitude, or is there something else you do?

Check out the 74181, by the way.

When you bring in a possibility like this, and something like the 8223,
which is, technically, TTL, you can do it in just a few chips. Heck, the
truth table is almost trivial:

signs action
+ + add
- + Subtract B from A
+ - Subtract A from B
- - add, but make the output sign negative

And, of course, if the command is "subtract", then just invert the truth
table, or something like that. ;-) Hmm. An xor or two and a couple of
steering gates, and as many full adders or 181s as you need; all you need
to do is connect the dots. ;-)

Good Luck!
Rich
Back to top
lemonjuice
Guest





Posted: Wed Feb 09, 2005 3:43 pm    Post subject: Re: Signed addition Reply with quote

On 8 Feb 2005 13:13:01 GMT, Juha Turunen <jtt7665@maa2.cc.lut.fi>
wrote:

Quote:
Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

So what I planned was to make a circuit that first converts the
numbers to 1's complement if the sign bit is 1 with XOR gates and
then adding them together. The carry out of the last adder must be
connected to the carry in of the first adder, right? The result is
converted back to the original number format.

Will this work?
On 8 Feb 2005 13:13:01 GMT, Juha Turunen <jtt7665@maa2.cc.lut.fi

wrote:

Quote:
Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

So what I planned was to make a circuit that first converts the
numbers to 1's complement if the sign bit is 1 with XOR gates and
then adding them together.
I don't know exactly what you mean but ...

You don't have to actually do the conversion if the sign bit is a 1.
Connect to your XOR gate a control signal 0 or 1. With control enabled
if your number is negative the conversion is automatic, if its not it
just passes through unchanged.

Quote:
The carry out of the last adder must be
connected to the carry in of the first adder, right? The result is
converted back to the original number format.

Yes which is a bit tedious with 1s complements , because the MSB must

be end around carried and added to produce the right result.
With a 2s complement you'd just have to discard the end around carry
easily implemented by connecting a NAND gate from the MSB of the input
to the MSB of the output.
Quote:
Will this work?
Yes but there are faster and less complex approaches then cascading

adders.
If you want top marks include an overflow detector. ie overflow =
carryin XOR carryout.
Good luck
Back to top
Juha Turunen
Guest





Posted: Wed Feb 09, 2005 5:53 pm    Post subject: Re: Signed addition Reply with quote

Fred Bloggs wrote:
Quote:


Juha Turunen wrote:
Fred Bloggs wrote:
Next time someone asks something maybe you could try to be more
constructive like the other ones that replied or maybe not reply
at all instead of wasting two minutes of your life writing a
semi-polite fuck you.

Ok- here's a not-so-polite f_ck you. Now for the not-so-constructive
criticism: it is clear that you are little poof punk bs artist, you are
a slouch and a shirker, as well as an uneducable low life enrolled in
the wrong course of study.

Let it alllllll out.. Everything's gonna be just fine... :)

--
Juha Turunen (turunen(at)iki.fi) elpuri@IRC | The problem with the global
Torikatu 5A4, 53100 Lappeenranta, Finland | village are all the global
GSM: 040-7092525, http://iki.fi/turunen/ | village idiots.
Back to top
Fred Bloggs
Guest





Posted: Wed Feb 09, 2005 7:04 pm    Post subject: Re: Signed addition Reply with quote

Juha Turunen wrote:
Quote:
Fred Bloggs wrote:


Juha Turunen wrote:

Fred Bloggs wrote:
Next time someone asks something maybe you could try to be more
constructive like the other ones that replied or maybe not reply
at all instead of wasting two minutes of your life writing a
semi-polite fuck you.

Ok- here's a not-so-polite f_ck you. Now for the not-so-constructive
criticism: it is clear that you are little poof punk bs artist, you are
a slouch and a shirker, as well as an uneducable low life enrolled in
the wrong course of study.


Let it alllllll out.. Everything's gonna be just fine... :)


Like I said- wise ass punk poof...
Back to top
Ratch
Guest





Posted: Tue Feb 15, 2005 1:07 pm    Post subject: Re: Signed addition Reply with quote

"Juha Turunen" <jtt7665@maa2.cc.lut.fi> wrote in message
news:slrnd0hh82.vhk.jtt7665@maa2.cc.lut.fi...
Quote:
Hi,

I need to add too signed binary numbers which are in a format such
that the MSB is the sign and the rest of the bits are the number's
absolute value. The addition can be done with combinatorial logic
and must be implemented with 74-series logic. Using such number
format probably doesn't make much sense, but homework assignments
rarely do :)

So what I planned was to make a circuit that first converts the
numbers to 1's complement if the sign bit is 1 with XOR gates and
then adding them together. The carry out of the last adder must be
connected to the carry in of the first adder, right? The result is
converted back to the original number format.

Will this work?

Yes, but it would be better to use 2's complement, because then you don't
have to worry about the carry around. Here's how. The three different ways
to represent -5 in 8 bits are as follows.

In signed-magnitude: 10000101
In signed-1's complement representation: 11111010
In signed-2's complement representation: 11111011

All positive numbers are represented the same. A signed-magnitude negative
number can be changed to a signed-2's complement by keeping the leftmost bit
1, inverting the 7 remaining bits, and then adding 1 to the 7 bit group.
The same procedure will also convert signed-2's complement back to signed
magnitude. After both numbers are converted to signed-2's complement,
simple add both 8 bit groups which include the signs together. Ignore any
sign carry out in all cases. If leftmost bit of the result is 1, then
convert it back to signed-magnitude. If the two numbers have different
signs, then no overflow can possibly occur. If the two numbers have the
same sign, then the result must also have the same sign, or an overflow has
occurred. Hope that helps. Ratch

Quote:

--
Juha Turunen (turunen(at)iki.fi) elpuri@IRC | The problem with the global
Torikatu 5A4, 53900 Lappeenranta, Finland | village are all the global
GSM: 040-7092525, http://iki.fi/turunen/ | village idiots.
Back to top
 
Post new topic   Reply to topic    Electronics Forum Index -> Design All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Home & Living New Topics
Contact Us
Powered by phpBB