Determining Sign of Binary Numbers & 4-Bit Subtracter

In summary, you can tell if a binary number is negative or positive by reading the flags or generating an interrupt for an overflow error.
  • #1
kElect
20
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
  • #2
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
 
  • #3
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.
 
  • #4
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.
 
  • #5
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:
  • #6

1. How do you determine the sign of a binary number?

The sign of a binary number is determined by its leftmost bit, also known as the most significant bit. If the leftmost bit is 0, the number is positive. If the leftmost bit is 1, the number is negative.

2. What is the purpose of a 4-bit subtracter in binary operations?

A 4-bit subtracter is a circuit used in binary operations to subtract two 4-bit binary numbers. It works by performing the subtraction operation on each bit, taking into account any borrow or carry bits, and providing the result as a 4-bit output.

3. How does a 4-bit subtracter handle negative numbers?

A 4-bit subtracter handles negative numbers by using a technique called two's complement. This involves inverting all the bits of the number and adding 1 to the result. This allows for negative numbers to be represented in binary form and easily subtracted from other binary numbers.

4. Can a 4-bit subtracter handle numbers larger than 4 bits?

Yes, a 4-bit subtracter can handle numbers larger than 4 bits by using multiple 4-bit subtracters in series. This allows for larger binary numbers to be subtracted in a step-by-step process, similar to how we perform subtraction with larger numbers in decimal form.

5. Are there any limitations to using a 4-bit subtracter in binary operations?

One limitation of using a 4-bit subtracter is that it can only handle numbers up to 4 bits in size. This means that if larger numbers need to be subtracted, multiple 4-bit subtracters need to be used. Additionally, a 4-bit subtracter cannot handle non-binary numbers, such as decimal numbers, and requires conversion to binary form before performing subtraction.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Linear and Abstract Algebra
Replies
2
Views
462
  • Engineering and Comp Sci Homework Help
Replies
1
Views
625
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Electrical Engineering
Replies
2
Views
1K
  • Computing and Technology
Replies
4
Views
767
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Replies
4
Views
929
  • Programming and Computer Science
Replies
3
Views
962
Replies
5
Views
1K
Back
Top