Download presentation
1
CMPUT 229 - Computer Organization and Architecture I
2. Number Systems Decimal Binary Addition Headecimal Two’s complement ASCII characters CMPUT Computer Organization and Architecture I
2
Positional Number System
329 923 3 2 9 9 2 3 9 2 3 9 2 3 329 923 CMPUT Computer Organization and Architecture I
3
CMPUT 229 - Computer Organization and Architecture I
Decimal numbers 329 923 3 100 9 100 3 10 + 91 9 1 329 923 CMPUT Computer Organization and Architecture I
4
Positional Number System
The same positional system works with different basis: 32913 92313 3 130 9 130 3 13 + 91 9 1 54210 155010 CMPUT Computer Organization and Architecture I
5
Binary System 1102 92316 122 + 121 + 020 9162 + 2161 + 3160
In computers we are mostly interested on bases 2, 8, and 16. 1102 92316 122 + 121 + 020 9 160 14 + 12 + 01 9 1 610 233910 CMPUT Computer Organization and Architecture I
6
CMPUT 229 - Computer Organization and Architecture I
Signed Integers Problem: given 2k distinct patterns of bits, each pattern with k bits, assign integers to the patterns in such a way that: The numbers are spread in an interval around zero without gaps. Roughly half of the patterns represent positive numbers, and half represent negative numbers. When using standard binary addition, given an integer n, the following property should hold: pattern(n+1) = pattern(n) + pattern(1) CMPUT Computer Organization and Architecture I
7
Signed Magnitude In a signed magnitude representation we
use the first bit of the pattern to indicate if it is a positive or a negative number.
8
Signed Magnitude What do we do with the pattern 1000?
9
Signed Magnitude Having two patterns to represent 0 is wasteful.
The signed magnitude representation has the advantage that it is easy to read the value from the pattern. But does it have the binary arithmetic property? For instance, what is the result of pattern(-1) + pattern(1)? pattern(-1) pattern(1) ?? PattPatel pp. 20
10
Signed Magnitude Having two patterns to represent 0 is wasteful.
The signed magnitude representation has the advantage that it is easy to read the value from the pattern. But does it have the arithmetic property? For instance, what is the result of pattern(-1) + pattern(1)? pattern(-1) pattern(1) 1010 = ?? PattPatel pp. 20
11
Signed Magnitude Having two patterns to represent 0 is wasteful.
The signed magnitude representation has the advantage that it is easy to read the value from the pattern. But does it have the arithmetic property? For instance, what is the result of pattern(-1) + pattern(1)? pattern(-1) pattern(1) 1010 = pattern(-2) PattPatel pp. 20
12
1’s Complement A negative number is represented
by “flipping” all the bits of a positive number. We still have two patterns for 0. It is still easy to read a value from a given pattern. How about the arithmetic property? Suggestion: try the folllowing = ?? = ?? 0 + 1 = ?? PattPatel pp. 20
13
CMPUT 229 - Computer Organization and Architecture I
2’s Complement a representation for negative numbers The leftmost bit is used to indicate +/- Positive number starts with 0, negative 1 A negative number is obtained by Convert the corresponding positive decimal number to a binary toggle all bits ( all 10 and all 0 1) Add 1 to the the binary obtained in the previous step CMPUT Computer Organization and Architecture I
14
2’s Complement A single pattern for 0. 1111 pattern(-1)
It holds the arithmetic property. But the reading of a negative pattern is not trivial. PattPatel pp. 20
15
Binary to Decimal Conversion
Problem: Given an 8-bit 2’s complement binary number: a7 a6 a5 a4 a3 a2 a1 a0 find its corresponding decimal value. Because the binary representation has 8 bits, the decimal value must be in the [-27; +(27-1)] =[-128;+127] interval. CMPUT Computer Organization and Architecture I PattPatel pp. 23
16
Binary to Decimal Conversion
a7 a6 a5 a4 a3 a2 a1 a0 Solution: negative false if (a7 = 1) then negative true flip all bits; compute magnitude using: if (negative = true) then CMPUT Computer Organization and Architecture I PattPatel pp. 24
17
Binary to Decimal Conversion (Examples)
Convert the 2’s complement integer to its decimal integer value. 1. a7 is 1, thus we make a note that this is a negative number and invert all the bits, obtaining: 2. We compute the magnitude: 3. Now we remember that it was a negative number, thus: CMPUT Computer Organization and Architecture I PattPatel pp. 24
18
Decimal to Binary Convertion
We will start with an example. What is the binary representation of 10510? Our problem is to find the values of each ai Because 105 is odd, we know that a0 = 1 Thus we can subtract 1 from both sides to obtain: CMPUT Computer Organization and Architecture I PattPatel pp. 24
19
Decimal to Binary Convertion (cont.)
Now we can divide both sides by 2 Because 52 is even, we know that a1 = 0 a2 = 0 a3 = 1 CMPUT Computer Organization and Architecture I PattPatel pp. 24
20
Decimal to Binary Convertion (cont.)
Thus we got: a1 = 0 a4 = 0 a5 = 1 a6 = 1 a2 = 0 a3 = 1 a0 = 1 10510 = CMPUT Computer Organization and Architecture I PattPatel pp. 25
21
Decimal to Binary Conversion (Another Method)
We can also use repeated long division: 105/2 = 52 remainder 1 52/2 = 26 remainder 0 26/2 = 13 remainder 0 13/2 = 6 remainder 1 6/2 = 3 remainder 0 3/2 = 1 remainder 1 1/2 = 0 remainder 1 CMPUT Computer Organization and Architecture I
22
Decimal to Binary Conversion (Another Method)
We can also use repeated long division: rightmost digit 105/2 = 52 remainder 1 52/2 = 26 remainder 0 26/2 = 13 remainder 0 13/2 = 6 remainder 1 10510 = 6/2 = 3 remainder 0 3/2 = 1 remainder 1 1/2 = 0 remainder 1 CMPUT Computer Organization and Architecture I
23
Decimal to Binary Conversion (Negative Numbers)
What is the binary representation of in 8 bits? We know from the previous slide that: = To obtain the binary representation of a negative number we must flip all the bits of the positive representation and add 1: Thus: = CMPUT Computer Organization and Architecture I PattPatel pp
24
Hexadecimal Numbers (base 16)
By convention, the characters 0x are printed in front of an hexadecimal number to indicate base 16. If the number 0xFACE represents a 2’s complement binary number, what is its decimal value? First we need to look up the binary representation of F, which is 1111. Therefore 0xFACE is a negative number, and we have to flip all the bits. CMPUT Computer Organization and Architecture I PattPatel pp
25
Hexadecimal Numbers (base 16)
It is best to write down the binary representation of the number first: 0xFACE = Now we flip all the bits and add 1: = 0x0532 Then we convert 0x0532 from base 16 to base 10: 0x0532 = 0 160 = 0 + 5 16 + 21 = = 0xFACE = CMPUT Computer Organization and Architecture I PattPatel pp
26
CMPUT 229 - Computer Organization and Architecture I
Binary Arithmetic Decimal 19 + 3 22 Binary 010011 010110 Binary 001110 000101 Decimal 14 - 9 5 910 = -910 = CMPUT Computer Organization and Architecture I PattPatel pp. 25
27
Overflow What happens if we try to add +9 with +11 in a 5-bit 2-complement representation? Decimal 9 + 11 20 Binary 01001 10100 = -12 ? The result is too large to represent in 5 digits, i.e. it is larger than = When the result is too large for the representation we say that the result has OVERFLOWed the capacity of the representation? CMPUT Computer Organization and Architecture I PattPatel pp. 27
28
CMPUT 229 - Computer Organization and Architecture I
Overflow Detection What happens if we try to add +9 with +11 in a 5-bit 2-complement representation? Decimal 9 + 11 20 Binary 01001 10100 = -12 ? We can easily detect the overflow by detecting that the addition of two positive numbers resulted in a negative result. CMPUT Computer Organization and Architecture I PattPatel pp. 28
29
Overflow (another example)
Could overflow happen when we add two negative numbers? Decimal - 12 + -6 -18 Binary 10100 01110 = +14 ? Again we can detect overflow by detecting that we added two negative numbers and got a positive result. Could we get overflow when adding a positive and a negative number? CMPUT Computer Organization and Architecture I PattPatel pp. 28
30
Sign-extension What is the 8-bit representation of +510? 0000 0101
What is the 8-bit representation of -510? What is the 8-bit representation of -510? CMPUT Computer Organization and Architecture I PattPatel pp. 27
31
Sign-extension What is the 8-bit representation of +510? 0000 0101
To sign-extend a number to a larger representation, all we have to do is to replicate the sign bit until we obtain the new length. What is the 16-bit representation of +510? What is the 8-bit representation of -510? What is the 8-bit representation of -510? CMPUT Computer Organization and Architecture I PattPatel pp. 27
32
CMPUT 229 - Computer Organization and Architecture I
Storing characters ASCII (American Standard Code for Information Interchange) One byte UTF-8 (8-bit Unicode Transformation Format) One to four bytes Coincides with ASCII Be able to represent any languages CMPUT Computer Organization and Architecture I
33
Endianess In the previous example, there are two ways to store at the address 0x and at the address 0x : 0x 0x 0x 0x 0x 0x 0x 0x 0x00 0x13 0xFF 0x97 Address Value 0x 0x 0x 0x 0x 0x 0x 0x 0x13 0x00 0x97 0xFF Address Value What is the difference? CMPUT Computer Organization and Architecture I
34
Little-End and Big-End
+1910 = (binary) Little end of +1910 Big end of +1910 +1910 = 0x (hexadecimal) = +1910 = 0xFFFF FF97 Little end of +1910 Big end of +1910 (binary) (hexadecimal) CMPUT Computer Organization and Architecture I
35
Endianess The question is: which end of the integer do we store first in memory? Big end of +1910 Little end of +1910 0x 0x 0x 0x 0x 0x 0x 0x 0x00 0x13 0xFF 0x97 Address Value 0x 0x 0x 0x 0x 0x 0x 0x 0x13 0x00 0x97 0xFF Address Value Big Endian Byte Order Little Endian Byte Order DECstations and Intel 80x86 are little-endians. Sun SPARC and Macintosh are big-endians. CMPUT Computer Organization and Architecture I
36
CMPUT 229 - Computer Organization and Architecture I
Floating Number How to represent a very large number? How about a number of the form x 10 Floating number IEEE standard -8 CMPUT Computer Organization and Architecture I
37
CMPUT 229 - Computer Organization and Architecture I
IEEE 754 Floating Number S exponent fraction (precision) S exponent – 127 N = x 1. Fraction x 2 CMPUT Computer Organization and Architecture I
38
CMPUT 229 - Computer Organization and Architecture I
Example 5 8 -6 CMPUT Computer Organization and Architecture I
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.