Determining Sign of Binary Numbers & 4-Bit Subtracter

Click For Summary
To determine if a binary number is negative or positive, the most significant bit (MSB) is typically used as the sign bit in two's complement representation, where a leading 1 indicates a negative number. For example, in a 4-bit system, the binary number 1111 can represent either -1 or 15, depending on whether the system treats it as signed or unsigned. The choice of representation affects how arithmetic operations are performed, with specific instructions for signed and unsigned operations in assembly language. When designing a 4-bit subtracter, it is essential to understand the specifications of the circuit being used, including whether it supports signed numbers and how it indicates overflow or errors. Ultimately, the interpretation of binary numbers can vary based on the programmer's design choices and the system's conventions.
kElect
Messages
20
Reaction score
0
how can you tell if a binary number is negative or positive?

1111 <--- how do you know if this is 15 or -1?

and for my project i have to make a 4 bit subtracter using LED lights to show 1's or 0's. Do I just leave it in 2's complement form?
 
Engineering news on Phys.org
hi there

that's an interesting Q and not one I cannot answer, haven't thought about that before
I will also be interested in seeing any response

in the mean time have a look at this www page and see if you can make sense of it ...
http://www.allaboutcircuits.com/vol_4/chpt_2/3.html

Dave
 
kElect said:
how can you tell if a binary number is negative or positive?

1111 <--- how do you know if this is 15 or -1?

and for my project i have to make a 4 bit subtracter using LED lights to show 1's or 0's. Do I just leave it in 2's complement form?

If you are able to do an operation like a multiply or divide and you can read the flags or generate an interrupt for an overflow error than that will tell you specifically if things are being treated as signed or unsigned implicitly.

The thing it will always depend on how the circuit treats the number. In an x86 type assembly environment we have IDIV and IMUL vs DIV and MUL for signed vs unsigned division and multiplication.

If you are using some circuit or device that is pre-made then I would just read the specifications and see how it treats the data to see if it uses signed numbers (MSB is sign) or unsigned (MSB is used to represent highest bit of actual data).

Usually if you have a circuit that has to do a specific operation like signed add or subtract, it will provide a flag of some sort (through an output pin) to say whether there was an error. In software it's done through either a flag or an interrupt but in hardware it will be given by an output pin. If the circuit or device has no error output of this kind then I would get a circuit or device that does if you are concerned about this.
 
kElect said:
how can you tell if a binary number is negative or positive?

1111 <--- how do you know if this is 15 or -1?

and for my project i have to make a 4 bit subtracter using LED lights to show 1's or 0's.
Have you been given the specs for your 4 bit subtractor? If so, what are they?
Do I just leave it in 2's complement form?
Are you allowed to display the answer with a negative sign prepended? That would be the most user friendly, I'd think.
 
I claim :

The sign of a binary number exists only in the mind of the programmer.

For any fixed number of bits the binary system is cyclic.
That is, it starts at zero where all bits are 0's and increments until all bits are 1's, meaning it's reached the largest number that can be represented with that many bits.
The next increment after all 1's flips it back to starting point, all 0's.

So - with N bits we can represent 2^N different values.
It is usually chosen to let half those values be negative and the other half be positive.
Further it is (i think) universally chosen to let all 0's represent zero.

Let us take a four bit counter for a simple example.
We'll start at zero, then increment the counter by one [STRIKE]seventeen[/STRIKE] sixteeen times, because 2^4 = sixteen and that's how many numbers we can represent with four bits.. [STRIKE]seven[/STRIKE] sixteenth increment should restart the count.
and we want to show the cyclic nature of binary counting.

0000 = zero
0001 = one
0010 = two
0011 = three
0100 = four
0101 = five
0110 = six
0111 = seven = largest positive number that can be represented with four bits IF you want luxury if signed numbers
1000 = -seven = largest negative number that can be represented with four bits IF you want luxury if signed numbers , or = +eight if you don't
1001 = -six = still counting up
1010 = -five
1011 = -four
1100 = -three
1101 = -two
1111 = -one if you want luxury of signed numbers, or = +fifteen if you don't
0000 = zero , still counting up, but the leading 1 disappeared off left end. (In a real machine thet'd be a carry bit but we are just studying nature of a 4-bit binary system here.)
0001 = one , and cycle starts again.

So you see that it is convenient but not necessary to use leftmost bit for sign.
We could as easily have used the four bits to count from zero to fifteen.

Count those increments to make sure i got [STRIKE]seventeen[/STRIKE] sixteen of them.

So to your question -

if the leftmost bit is set to 1 it is USUALLY a negative number because that's the convention.
But since you are building the machine the choice is really up to you.
When Mother Nature gave us the binary system she left it up to us how to use it.

And that's why chiro mentioned signed vs unsigned arithmetic.

Is that any help?

old jim
 
Last edited:
I am trying to understand how transferring electric from the powerplant to my house is more effective using high voltage. The suggested explanation that the current is equal to the power supply divided by the voltage, and hence higher voltage leads to lower current and as a result to a lower power loss on the conductives is very confusing me. I know that the current is determined by the voltage and the resistance, and not by a power capability - which defines a limit to the allowable...

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
11K
Replies
5
Views
2K
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K