• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

question about complements. (1 Viewer)

-X-

Member
Joined
Aug 10, 2003
Messages
481
Gender
Undisclosed
HSC
N/A
Hi, i've just got something really confusing me. If for example i want to represent -1 in 10's complement form. This will then equal to 999 right? But then, what if the computer wants to represent the actual number, '999'. How will it know whether it is representing a negative number, '-1' or the actual "999"? The Alan Fowler textbookd doesnt explain this.

Thanks, hope you understood me. :)
 

Ragerunner

Your friendly HSC guide
Joined
Apr 12, 2003
Messages
5,472
Location
UNSW
Gender
Male
HSC
2003
Is this for option topic? or do we need this for the core?
 

enak

Limbo
Joined
Oct 18, 2002
Messages
1,046
Location
Sydney
Gender
Undisclosed
HSC
N/A
Sounds like the option, but wtf are you talking about 999 and -1. Two's compliment in binary not ten's compliment, no such thing is in the syllabus or course.

Computer's dont understand base(10), :)
 

-X-

Member
Joined
Aug 10, 2003
Messages
481
Gender
Undisclosed
HSC
N/A
Option topic, "s/w developers view of h/ware".

BTW, with my above question, i know computers only read in binary, i only used decimal for simplicity. :D

Edit: enak was too fast for me. :D
 

enak

Limbo
Joined
Oct 18, 2002
Messages
1,046
Location
Sydney
Gender
Undisclosed
HSC
N/A
Lol, oh well, have a look at Sam Davies text book, that's the only good sdd text book I have seen.
 

fatmuscle

Active Member
Joined
Jul 6, 2002
Messages
3,707
Location
Hornsby
Gender
Male
HSC
2001
Originally posted by enak
Lol, oh well, have a look at Sam Davies text book, that's the only good sdd text book I have seen.

Sam should have his own open day, set up a stall, sign books all day.
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
Originally posted by -X-
Hi, i've just got something really confusing me. If for example i want to represent -1 in 10's complement form. This will then equal to 999 right? But then, what if the computer wants to represent the actual number, '999'. How will it know whether it is representing a negative number, '-1' or the actual "999"? The Alan Fowler textbookd doesnt explain this.

Thanks, hope you understood me. :)
The computer has to understand the rules of the game (or the rules of the number system). If a computer was to use a 10's complement system like you discuss, then it would also need to know that 0-499 were positives (or more accurately non-negatives), and that 500-999 were negatives.

It's the same for two's complement in binary, the computer knows the first bit represents a negative power of two. In binary you only need to look at the highest order bit, as it conveniently splits the range into two equal ranges, the negatives when the bit is set (ie 1) and the non-negatives when it is not (ie 0).

The equivalent of this for your three digit base 10 system would be any number starting with 5, 6, 7, 8 or 9 is negative and any number starting with 0, 1, 2, 3 or 4 is non-negative. Your system will work; try doing some arithmetic...

(1) -1 + 1 using your system is performed as 999 + 1 = 1000, ignore the leading 1 and your answer is 0

(2) 10 - 20 using your system is performed as 10 + 980 = 990, 990 converts to -10.

(3) -6 * -3 using your system is performed as 994 * 997 = 991018, retain just the three digits used by your system, so the answer is 18

(4) 100 * 6 = 600, which in your system is -400, so just like binary twos complement, problems occur when answers are outside the range represented.

HTH
Sam
 

-X-

Member
Joined
Aug 10, 2003
Messages
481
Gender
Undisclosed
HSC
N/A
Re: Re: question about complements.

Originally posted by SamD
(4) 100 * 6 = 600, which in your system is -400, so just like binary twos complement, problems occur when answers are outside the range represented.

HTH
Sam
Ok but how is the problem solved? Here's an example in binary:
11111111 = 255
But "-1" is also = 11111111.

So then how would the computer represent the # 255? Would an instruction be sent saying "this is in 2's complement" when representing a -ve number? Oh and is this the problem that occurs you are talking about?


Thanks a lot for your explanation though. :)
 

enak

Limbo
Joined
Oct 18, 2002
Messages
1,046
Location
Sydney
Gender
Undisclosed
HSC
N/A
When you deal with 8-bit numbers, the first bit isn't included in the positive integer representation, hence you would have to move to 16-bits and use the remaining 15-bits for the integer representation and the first bit as the sign.

edit: shit i'm thinking sign and modulas :S i'm a little tired :(
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
If you're only using 8 bits then you can't represent 255 at all. The range is -128 to 127 and that's it.

In reality, applications don't often use 8 bit twos complement, however 16 bit twos complement is very common. If you've got MS-Access, create a table with some field. Set the datatype to number then the filed size to integer. Save it and try entering numbers outside the range -32768 to 32767. You'll get an error message.

HTH
Sam
 

-X-

Member
Joined
Aug 10, 2003
Messages
481
Gender
Undisclosed
HSC
N/A
Originally posted by SamD
If you're only using 8 bits then you can't represent 255 at all. The range is -128 to 127 and that's it.

In reality, applications don't often use 8 bit twos complement, however 16 bit twos complement is very common. If you've got MS-Access, create a table with some field. Set the datatype to number then the filed size to integer. Save it and try entering numbers outside the range -32768 to 32767. You'll get an error message.

HTH
Sam
But thats taking sign and modulas into account? For e.g - take my previous example again this time taking -128:

11111111 (8bit) = -128
But "-1" is also = 11111111 (2's complement).

Ok im really confused now, i dont think i know what im asking now. :D
 

-X-

Member
Joined
Aug 10, 2003
Messages
481
Gender
Undisclosed
HSC
N/A
Ok i think i understand what im asking. But ill go step by step so neither me or anyone gets confused. :D

Someone answer this, if the binary number 11111111 (8 bit) is sent to the processor, what would it interpret it as?
 

-X-

Member
Joined
Aug 10, 2003
Messages
481
Gender
Undisclosed
HSC
N/A
Originally posted by fatmuscle
muck around with the digits
Ahh ok thanks for that:
Heres the screenshot which describes what im talking about:


Now firstly, by signed, does it mean 2's complement? I would have thought a signed 8 bit integer = 0 to 255 and unsigned = -128 to 127 (what samd said).

Ok, so now according to that program, 1111 1111 can be represented as "-1" AND "255". Now how would the computer know what "1111 1111" is representing? Would there be some sort of instruction telling it whether this binary (1111 1111) is in 2's complement form or not?

Thanks again. :)
 

wogboy

Terminator
Joined
Sep 2, 2002
Messages
653
Location
Sydney
Gender
Male
HSC
2002
Here's an important fact when representing any number in x-bit 2's complement form:

the highest number you can possibly store (H) is:

H = 2^(x-1) - 1

the lowest number that you can possbily store (L) is:

L = - 2^(x-1)

e.g. when x=8 (8 bit 2's complement), then H = 2^7 - 1 = 127. L = - 2^7 = -128

So you can represent any number from -128 up to 127. Any number outside this range is invalid. So you can see that with a finite number of bits, you cannot store every possible integer that exists! If this wasn't the case, then you could store an infinite amount of data on a floppy disk!

For the binary 2's complement number 11111111, how did you get -128? -128 is 10000000. In order to find -128 in 2's complement form:

1. First find +128 in binary (10000000)
2. Change all the 1's to 0's and all the 0's to 1's. (01111111)
3. And last but not least add 1 to this number (10000000)

This is the way to convert any negative decimal integer to 2's complement form. Converting a positive decimal integer to 2's complement form is straightforward (just convert it to binary and you're done).

To convert from 2's complement form back to decimal again, simply work backwards.
 

-X-

Member
Joined
Aug 10, 2003
Messages
481
Gender
Undisclosed
HSC
N/A
Originally posted by wogboy

For the binary 2's complement number 11111111, how did you get -128? -128 is 10000000.
The program says "signed". And i was asking if by "signed", they meant "2's complement". Cause saying signed is totaly different to saying 2s complement. Heres a quote showing what i mean:
As shown in Table 3.1, unsigned short integers, assuming that they are two bytes, can hold a value only up to 65,535. signed short integers split their values between positive and negative numbers, and thus their maximum value is only half that of the unsigned.
from http://www.informit.com/isapi/produ...-4782-9A96-05825F8E6E5B}/content/articlex.asp
So a signed 8 bit integer has range a of -128 to 127. But an unsigned 8 bit integer has a range from 0 to 255.
 
Last edited:

-X-

Member
Joined
Aug 10, 2003
Messages
481
Gender
Undisclosed
HSC
N/A
Originally posted by wogboy

1. First find +128 in binary (10000000)
2. Change all the 1's to 0's and all the 0's to 1's. (01111111)
3. And last but not least add 1 to this number (10000000)
Ok heres my problem:
+128 = 10000000
and
-128 is also (2's complement) = 10000000 according to you.

Now, how will the processor know whether its dealing with "-128" or "+128". Thats my problem / question.

My brain hurts.
 

-X-

Member
Joined
Aug 10, 2003
Messages
481
Gender
Undisclosed
HSC
N/A
I think i got it now.
The minute the leading number is '1' it is automatically read as a 2's complement negative number (as SamD said). Now to represent:
-128 = 1000000 as wogboy said.
to represent +128:
I would have to change the binary to 16 bit form:
ie "00000000 10000000" -> the computer reads this as a +ve number (leading bit is 0).

So now, there is no way a binary can represent 2 numbers when you stick to the number of bits your using.

Am i right now? My brain really hurts. :p
 
Last edited:

-X-

Member
Joined
Aug 10, 2003
Messages
481
Gender
Undisclosed
HSC
N/A
Now i know what that "signed and unsigned" means in the program. :=)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top