How to Add Two Sign Magnitude Numbers?

조회 수: 5 (최근 30일)
arina octave
arina octave 2015년 11월 12일
댓글: Walter Roberson 2015년 11월 16일
Hi all, anyone have the idea of how to add two sign magnitude numbers? Well, I think about binary adder but I just get confused about the sign and handling the overflow. Any advice?
Thank you.

채택된 답변

Walter Roberson
Walter Roberson 2015년 11월 12일
binary adders are fine if you have binary input, but they are not very good if you are, for example, using Variable Base Arithmetic such as times represented in hours minutes and seconds.
Before you can design an addition routine for the numbers, you are going to need to define the properties of the source representations and of the desired output representations.
  댓글 수: 2
arina octave
arina octave 2015년 11월 16일
편집: arina octave 2015년 11월 16일
Hi Walter, let's say that I have two floating point numbers which I convert to fixed-point format using either fi() or sfi() function. So, if I convert the result by using bin function, as example :
a = sfi(3,6,4);
b = sfi(-2,6,4);
a.bin;
b.bin;
is there any way to add the a.bin and b.bin by using a binary adder? What kind of binary adder do I need? Which I just realize that the bin function is producing the result in two's-complement format, not in sign-magnitude format.
Walter Roberson
Walter Roberson 2015년 11월 16일
I had to look in several places to confirm, but I do find a statement Over Here that signed values are represented as Two's Complement by the Fixed Point Toolbox, not as Sign/Magnitude.
If you have the .bin of a pair of twos-complement values that have the same scaling (and other properties) and do not have special fimath properties, then you can use a traditional full adder circuit, which you can easily find by using (for example) Google Image Search. If you are using the fixed point toolbox and you are using HDL Coder then it is able to generate an adder circuit for you automatically.
If you have a pair of sign/magnitude binary values, then you use the xor of their sign to determine whether to apply a twos complement of one of the values before entering a full adder circuit. You can locate diagrams through Google Image Search.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by