Download presentation
Presentation is loading. Please wait.
Published byNoah Fitzgerald Modified over 8 years ago
1
Integer Representation for People Computer Organization and Assembly Language: Module 3
2
Motivation u The representation of numbers is made difficult because of the discrete nature of computer representation u Not all numbers can be represented in a computer u The chosen method of representation affects the ease by which arithmetic operations are performed
3
Weighted Positional Notation u Use the position of the symbol to indicate the value u By assigning each position the appropriate power of the base, we can get a unique representation of numbers in that base Decimal System (Base 10) Given a sequence of n digits d 0,d 1,…,d n-1 d n-1.10 n-1 + … + d 1.10 1 + d 0.10 0
4
Weighted Positional Notation u In general, given a sequence of n digits s 0,s 1,…,s n-1 and a base b, s n-1.b n-1 + … + s 1.b 1 + s 0.b 0 yields a unique integer N u s 0 is the least significant digit u s n-1 is the most significant digit u The most significant symbol can not be zero
5
Weighted Positional Notation u Any positive integer value can be used as the base or radix for a weighted positional notation u For bases less than or equal to 10, a subset of the ten decimal digits can be used binary (base 2) octal (base 8) u For bases more than 10, new symbols will have to be introduced hexadecimal (base16) a=10, b=11, c=12, d=13, e=14, f=15
6
Weighted Positional Notation u A subscript is used to indicate the base of the number in typeset A number without a subscript is assumed to be base 10 Not an option while programming in MAL u In MIPS assembly language, hexadecimal representation begins with 0x 0x10 (= decimal 16) u So the following instructions are identical li $v0, 0x12 li $v0, 18
7
Representations in Different Radices binary hexdecimalbinaryhexdecimal 00000100088 00111100199 010221010a10 011331011b11 100441100c12 101551101d13 110661110e14 111771111f15
8
Binary and Hexadecimal u Discriminating between two symbols is currently cheaper in digital circuitry than three or more, thus binary is the representation for computers u Since bits can be grouped into three to obtain octal value and into four to obtain hexadecimal value, it is much easier for humans to work with octal or hexadecimal representations. Octal is no longer very common; we will focus on hexadecimal u Binary to hexadecimal conversion is more direct than binary to decimal conversion. Reason: 16 is a power of 2
9
Binary to Hexadecimal u To convert from binary to hexadecimal: Starting with the least significant bit, partition the bits of the binary representation into groups of 4 The most significant group may have fewer than 4 members Add zeroes to the left of the most significant group until it contains 4 bits Convert each group of four bits into the hexadecimal symbol corresponding to that bit pattern
10
Binary and Hexadecimal Example: Convert 11011 2 to hexadecimal. binary 00011011 hexadecimal 1 b hence: 11011 2 = 1b 16
11
Hexadecimal to Binary u To convert from binary to hexadecimal: Convert each hexadecimal symbol to a group of 4 bits corresponding to that value Eliminate leading zeroes Example: Convert 2bc1 16 to binary. hexadecimal 2 b c 1 binary 00101011 1100 0001 hence: 2bc1 16 = 10101111000001 2
12
Conversion to Decimal Given a sequence of base-r digits s n-1... s 1 s 0 convert the sequence into a decimal number N using: N = s n-1 *b n-1 + … + s 1 *b 1 + s 0 *b 0
13
Conversion to Decimal Convert 10 0110 2 to decimal. N = 1*2 5 + 0*2 4 + 0*2 3 + 1*2 2 + 1*2 1 + 0*2 0 = 38 Convert 3b2 16 to decimal. N = 3*16 2 + 11*16 1 + 2*16 0 = 946 Convert 370 8 to decimal. N = 3*8 2 + 7*8 1 + 0*8 0 = 192 + 56 + 0 = 248
14
Decimal Binary or Hexadecimal Repeated division by 2 or 16 Example: Convert 292 to hexadecimal. 292/16 = 18 R 4 18/16 = 1 R 2 1/16 = 0 R 1 292 = 124 16 Conversion from Decimal When the quotient is less than 16, the process ends
15
Conversion from Decimal u Convert 42 to hexadecimal 42/16 = 2 R 10 (but 10 = a 16 ) 2/16 = 0 R 242 = 2a 16 u Convert 109 to binary 109/2 = 54 R 1 54/2 = 27 R 0 27/2 = 13 R 1 13/2 = 6 R 1 6/2 = 3 R 0 3/2 = 1 R 1 1/2 = 0 R 1109 = 1101101 2
16
Shortcut: convert to hexadecimal u It is sometimes easier to convert from binary to hexadecimal, then to decimal, instead of converting directly to decimal 11101010110110 = 0011 1010 1011 0110 = 3 a b 6 = 3*16^3 + 10*16^2 + 11*16 + 6 = 3*4096 + 10*256 + 176 + 6 = 12198 + 2560 + 182 = 12198 + 2742 = 14940
17
Shortcut: convert to hexadecimal u The converse is also true: converting from decimal to hexadecimal, then to binary generally requires far fewer steps than converting directly to binary 278/16 = 17 R 6 17/16 = 1 R 1 1/16 = 0 R 1 278 = 116 16 = 0001 0001 0110 2 = 100010110 2
18
Representing Numbers u Choosing an appropriate representation is a critical decision a computer designer has to make u The chosen representation must allow for efficient execution of primitive operations u For general-purpose computers, the representation must allow efficient algorithms for addition of two integers determination of additive inverse
19
Representing Numbers u With a sequence of N bits, there are 2 N unique representations u Each memory cell can hold N bits u The size of the memory cell determines the number of unique values that can be represented u The cost of performing operations also increases as the size of the memory cell increases u It is reasonable to select a memory cell size such that numbers that are frequently used are represented
20
Binary Representation u The binary, weighted positional notation is the natural way to represent non-negative numbers. u MAL numbers the bits from right to left, beginning with 0 as the least significant digit. 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
21
Modulo Arithmetic u Consider the set of number {0, …,7} u Suppose all arithmetic operations were finished by taking the result modulo 8 u 3 + 6 = 9, 9 mod 8 = 1 3 + 6 = 1 u 3*5 = 15, 15 mod 8 = 7 3 * 5 = 7 1 2 3 4 5 6 7 0
22
Modulo Arithmetic: Additive Inverse u What is the additive inverse of 7? u 7 + x = 0 u 7 + 1 = 0 u 0 and 4 are their own additive inverses u Does each number also have a multiplicative inverse? 1 2 3 4 5 6 7 0
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.