# Signed BinaryWatch

This discussion is closed.
Thread starter 13 years ago
#1
How do I work out a negative number?
I know that the starting bit of the signed (8-bits) is the signed part.

E.g. 0 = possative
1 = negative

Now if I wanted -8, how would I write this as an 8 bit number? Can some one please explain to me.
0
13 years ago
#2
8 bits, or a byte, is a one word integer (word = byte)
A byte can represent either a signed integer or an unsigned integer.
An unsigned integer ranges in value from 0 to 255
A signed integer ranges in value from -128 to 127.
I'm assuming you know about the binary representation of a number in bits.
bit 1 is 2^0
bit 2 is 2^1
bit 3 is 2^2
bit 4 is 2^3
bit 5 is 2^4
bit 6 is 2^5
bit 7 is 2^6
bit 8 is 2^7
(bit 1 is the right-most bit)

So, in an unsigned integer, 183, say. This is made up by 128 + 32 + 16 + 4 + 2 + 1 = 2^7 + 2^5 + 2^4 + 2^2 + 2^1 + 2^0
2^7 + 2^5 + 2^4 + 2^2 + 2^1 + 2^0 = 1.(2^7) + 0(2^6) + 1.(2^5) + 1.(2^4) + 0.(2^3) + 1.(2^2) + 1.(2^1) + 1.(2^0) = 1011 0111.

If we have an unsigned or signed integer, 55, say. Then this is made up by 32 + 16 + 4 + 2 + 1 = 2^7 + 2^5 + 2^4 + 2^2 + 2^1 + 2^0
2^5 + 2^4 + 2^2 + 2^1 + 2^0 = 0.(2^7) + 0(2^6) + 1.(2^5) + 1.(2^4) + 0.(2^3) + 1.(2^2) + 1.(2^1) + 1.(2^0) = 0011 0111.

If the number is a negative (signed) integer, then we treat the 8th bit as negative. But the 8th bit is 2^7 = 128. So the 8th bit is actually treated as -128.
So if we have a -ve number, -73, say. Then -73 = -128 + 55.
-128 is now represented by 2^7 = 1000 0000
55 is represented by 0011 0111
Code:
```1000 0000	-128
0011 0111	55
========	===
1011 0111	-73
====================```
Summary
=======
To get a -ve number in binary, treat the 8th bit as -128 then use the remaining 7 bits to give a +ve number which when added to -128 will give you the -ve number you want.

Question for you: What is -8 in 8-bit binary as a signed word?
0
13 years ago
#3
By convention (well, the learning convention, anyway), if you have an n-bit number, the first bit is the "sign" bit.. a 1 means a negative sign. if it's 1, it means that the (n-1) bits that follow it represent a negative number.

so, an 8 bit integer, instead of being able to represent 0 to 2^8 - 1, it can only represent 0 up to 2^7 - 1. Simple reason: you're using 1 bit to represent a negative /positive sign, rather than to add an extra digit.

Which leaves us the problem of how to convert a positive to negative number.

I'm assuming you know about binary, but not the 2s (or 1s) complement. The general principle is that you can get the answer to a subtraction problem by Adding. For a base 10 example:

7 - 6 --> 7 + (10 - 6) = 7 + 4 = 11 ---> cut out the 10s digit --> 1.

Why? Well.
7 - 6 = 7 + (10 - 6) [- 10 ] = 7 + 4 [- 10 ] = 11 - 10 = 1.

---

Similarly, 81 - 36 ---> 81 + (100 - 36) = 81 + 64 = 145 --> drop the 100 digit --> 45. For very similar reasons, i'm sure you see.

Seems a long way to go, doesn't it? That's just mental justification.

Can we do this digit by digit? 100 - 36 itself can be generalized into 90 - 30 + 9 - 6 + 1. In other words, we just subtract each digit from 9, and then add 1 in the end, and we get the number you're supposed to add.

In base 10, and without adding the 1 at the end, this is called the 9s complement, since you're taking the difference between the number and 9. If you do add the 1, it's called the 10s complement, since you correctly get the base 10 number you have to add to get the correct subtraction form.

It still dosen't make sense, huh? "What's the point in all this jazz when we have to subtract from 9 anyway?" Well, it does make sense in binary.

Yup, with a base with only 1s and 0s, it's pretty easy to see what, say, 10000 - 1010 is.

It can be generalized into [1000 - 1000 ] + [100 - 000] + [10 - 10] - [1 - 0] + 1. So, basically, you replace all digits with the opposite digit (0 if 1, 1 if 0) in the number you're subtracting from it. Then don't forget to add 1 at the end. If you don't add 1, it's the 1s complement.. if you do, it's the 2s complement.

From this, you can find the signed bit. if you add this to the top, you get the difference! If you get a carry bit at the very end, it means the answer's positive. Mm, check this for yourself, i'm just bsing here
X
new posts
Latest
My Feed

### Oops, nobody has postedin the last few hours.

Why not re-start the conversation?

see more

### See more of what you like onThe Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

### University open days

• University of East Anglia
All Departments Open 13:00-17:00. Find out more about our diverse range of subject areas and career progression in the Arts & Humanities, Social Sciences, Medicine & Health Sciences, and the Sciences. Postgraduate
Wed, 30 Jan '19
• Solent University
Careers in maritime Undergraduate
Sat, 2 Feb '19
• Sheffield Hallam University
City and Collegiate Campus Undergraduate
Sun, 3 Feb '19

### Poll

Join the discussion

#### Do you have a role model?

Yes - I know them personally (295)
25.88%
Yes - they're famous (291)
25.53%
No I don't (554)
48.6%