SlideShare a Scribd company logo
1 of 46
Download to read offline
© Christian Jacob
Chapter Overview
Chapter 4
Binary Data Representation
and
Binary Arithmetic
4.1 Binary Data Representation
4.2 Important Number Systems for Computers
4.2.1 Number System Basics
4.2.2 Useful Number Systems for Computers
4.2.3 Decimal Number System
4.2.4 Binary Number System
4.2.5 Octal Number System
4.2.6 Hexadecimal Number System
4.2.7 Comparison of Number Systems
4.3 Powers of 2
© Christian Jacob
Chapter Overview
4.4 Conversions Between Number Systems
4.4.1 Conversion of Natural Numbers
4.4.2 Conversion of Rational Numbers
4.5 Binary Logic
4.6 Binary Arithmetic
4.7 Negative Numbers and Complements
4.7.1 Problems of Signed Number Representation
4.7.2 1-Complement ((B-1)-Complement)
4.7.3 2-Complement (B-Complement)
4.8 Floating Point Numbers
4.8.1 Mantissa and Exponent
4.8.2 Floating Point Arithmetics
4.8.3 Limited Precision
4.9 Representation of Strings
4.9.1 Representation of Characters
4.9.2 Representation of Strings
Page 3 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Prev Next Last
4.1 Binary Data Representation
Bit: smallest unit of information
yes / no, on / off, L / 0, 1 / 0, 5V / 0V
Byte: group of 8 bits
--> 28 = 256 different states
Word: the number of bits (word length) which
can be processed by a computer in a single
step (e.g., 32 or 64)
--> machine dependent
Representation:
n-1
2n-1
3
8
2
4
1
2
0
1
. . .
Page 4 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Prev Next Last
• The word size in any given computer is fixed.
Example: 16-bit word
⇒ every word (memory location) can hold a 16-bit pattern, with
each bit either 0 or 1.
How many distinct patterns are there in a 16-bit word?
• Each bit has 2 possible values: 0 or 1
⇒ 1 bit has 2 distinct patterns: 0, 1
• With 2 bits, each position has 2 possible values: 00, 01, 10, 11
⇒ 22 = 4 distinct bit patterns
Page 5 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Prev Next Last
• With 3 bits, again each position can be either 0 or 1:
000 100
001 101
010 110
011 111
⇒ 23 = 8 distinct bit patterns
• In general, for n bits (a word of length n) we have 2n distinct bit
patterns.
• NOTE: What these bit patterns mean depends entirely on the
context in which the patterns are used.
Page 6 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Important Number Systems for Computers Prev Next Last
4.2 Important Number Systems for Computers
4.2.1 Number System Basics
• Number systems, as we use them, consist of
- a basic set of digits (or letters); example:
- a base (how many digits); example:
• A number is a linear sequence of digits.
• The value of a digit at a specific position depends on its “assigned
meaning” and on its position.
• The value of a number is the sum of these values.
Number: with word length
Value:
Z Z 0 1 2 … 9, , , ,{ }=
B Z= B Z 10= =
N
NB dn 1– dn 2– …d1d0= n
NB di B
i
⋅
i 0=
n 1–
∑ dn 1– B
n 1–
dn 2– B
n 2–
… d1B
1
d0B
0
+ + + += =
Page 7 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Important Number Systems for Computers Prev Next Last
4.2.2 Useful Number Systems for Computers
Name Base Digits
dual
binary
2 0, 1
octal 8 0, 1, 2, 3, 4, 5, 6, 7
decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
hexadecimal
sedecimal
16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Page 8 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Important Number Systems for Computers Prev Next Last
4.2.3 Decimal Number System
;
• Each position to the left of a digit increases by a power of 10.
• Each position to the right of a digit decreases by a power of 10.
Example:
4769210 = 2 · 100 +
9 · 101 +
6 · 102 +
7 · 103 +
4 · 104
= 2 + 90 + 600 + 7000 + 40000
Z 0 1 2 3 4 5 6 7 8 9, , , , , , , , ,{ }= B 10=
Page 9 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Important Number Systems for Computers Prev Next Last
4.2.4 Binary Number System
;
• Each position to the left of a digit increases by a power of 2.
• Each position to the right of a digit decreases by a power of 2.
Example:
101110012 = 1 · 20 +
0 · 21 +
0 · 22 +
1 · 23 +
1 · 24 +
1 · 25 +
0 · 26 +
1 · 27 = 1 + 8 + 16 + 32 + 128 =18510
Z 0 1,{ }= B 2=
Page 10 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Important Number Systems for Computers Prev Next Last
Counting in Binary
Decimal Dual Decimal Dual
0 00 000 16 10 000
1 00 001 17 10 001
2 00 010 18 10 010
3 00 011 19 10 011
4 00 100 20 10 100
5 00 101 21 10 101
6 00 110 22 10 110
7 00 111 23 10 111
8 01 000 24 11 000
9 01 001 25 11 001
10 01 010 26 11 010
11 01 011 27 11 011
12 01 100 28 11 100
13 01 101 29 11 101
14 01 110 30 11 110
15 01 111 31 11 111
Page 11 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Important Number Systems for Computers Prev Next Last
4.2.5 Octal Number System
;
• Each position to the left of a digit increases by a power of 8.
• Each position to the right of a digit decreases by a power of 8.
Example:
124038 = 3 · 80 +
0 · 81 +
4 · 82 +
2 · 83 +
1 · 84
= 3 · 1 + 0 · 8 + 4 · 64 + 2 · 512 + 1 · 4096
= 537910
Z 0 1 2 3 4 5 6 7, , , , , , ,{ }= B 8=
Page 12 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Important Number Systems for Computers Prev Next Last
Counting in Octal
Decimal Octal Decimal Octal
0 0 0 16 2 0
1 0 1 17 2 1
2 0 2 18 2 2
3 0 3 19 2 3
4 0 4 20 2 4
5 0 5 21 2 5
6 0 6 22 2 6
7 0 7 23 2 7
8 1 0 24 3 0
9 1 1 25 3 1
10 1 2 26 3 2
11 1 3 27 3 3
12 1 4 28 3 4
13 1 5 29 3 5
14 1 6 30 3 6
15 1 7 31 3 7
Page 13 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Important Number Systems for Computers Prev Next Last
4.2.6 Hexadecimal Number System
;
Each position to the left of a digit increases by a power of 16.
Each position to the right of a digit decreases by a power of 16.
Example:
FB40A16 = 10 · 160 +
0 · 161 +
4 · 162 +
11 · 163 +
15 · 164
= 10 · 1 + 0 · 16 + 4 · 256 + 11 · 4096 + 15 · 65536
= 1,029,13010
Z 0 1 2 3 4 5 6 7 8 9 A B C D E F, , , , , , , , , , , , , , ,{ }= B 16=
Page 14 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Important Number Systems for Computers Prev Next Last
Counting in Hexadecimal
Decimal Hexadecimal Decimal Hexadecimal
0 0 0 16 1 0
1 0 1 17 1 1
2 0 2 18 1 2
3 0 3 19 1 3
4 0 4 20 1 4
5 0 5 21 1 5
6 0 6 22 1 6
7 0 7 23 1 7
8 0 8 24 1 8
9 0 9 25 1 9
10 0 A 26 1 A
11 0 B 27 1 B
12 0 C 28 1 C
13 0 D 29 1 D
14 0 E 30 1 E
15 0 F 31 1 F
Page 15 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Important Number Systems for Computers Prev Next Last
4.2.7 Comparison of Number Systems
Decimal Dual Octal Hexadecimal Decimal Dual Octal Hexadecimal
0 00 000 0 0 0 0 16 10 000 2 0 1 0
1 00 001 0 1 0 1 17 10 001 2 1 1 1
2 00 010 0 2 0 2 18 10 010 2 2 1 2
3 00 011 0 3 0 3 19 10 011 2 3 1 3
4 00 100 0 4 0 4 20 10 100 2 4 1 4
5 00 101 0 5 0 5 21 10 101 2 5 1 5
6 00 110 0 6 0 6 22 10 110 2 6 1 6
7 00 111 0 7 0 7 23 10 111 2 7 1 7
8 01 000 1 0 0 8 24 11 000 3 0 1 8
9 01 001 1 1 0 9 25 11 001 3 1 1 9
10 01 010 1 2 0 A 26 11 010 3 2 1 A
11 01 011 1 3 0 B 27 11 011 3 3 1 B
12 01 100 1 4 0 C 28 11 100 3 4 1 C
13 01 101 1 5 0 D 29 11 101 3 5 1 D
14 01 110 1 6 0 E 30 11 110 3 6 1 E
15 01 111 1 7 0 F 31 11 111 3 7 1 F
Page 16 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Powers of 2 Prev Next Last
4.3 Powers of 2
N 2N N 2N
0 1 17 131,072
1 2 18 262,144
2 4 19 524,288
3 8 20 1,048,576
4 16 21 2,097,152
5 32 22 4,194,304
6 64 23 8,388,608
7 128 24 16,777,216
8 256 25 33,554,432
9 512 26 67,108,864
10 1,024 27 134,217,728
11 2,048 28 268,435,456
12 4,096 29 536,870,912
13 8,192 30 1,073,741,824
14 16,384 31 2,147,483,648
15 32,768 32 4,294,967,296
16 65,536 33 8,589,934,592
Page 17 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Conversions Between Number Systems Prev Next Last
4.4 Conversions Between Number Systems
4.4.1 Conversion of Natural Numbers
Base 10 ⇒ Base B Conversion
We use the metod of iterated division to convert a number of
base 10 into a number of base .
1. Divide the number by : whole number & remainder .
- Take as the next number to be divided by .
- Keep as the next left-most digit of the new number .
2. If is zero then STOP, else set and go to step 1.
N10
NB B
N10 B N R
N B
R NB
N N10 N=
Page 18 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Conversions Between Number Systems Prev Next Last
Example: 102010 = ? 8
Number to be converted: ; target base
Step 1: 1020 : 8 = 127 Remainder: 4 127 · 8 = 1016
Step 2: 127 : 8 = 15 Remainder: 7 15 · 8 = 120
Step 3: 15 : 8 = 1 Remainder: 7 1 · 8 = 8
Step 4: 1 : 8 = 0 Remainder: 1
⇒ 102010 = 17748
N10 1020= B 8=
Page 19 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Conversions Between Number Systems Prev Next Last
Base B ⇒ Base 10 Conversion
We use the metod of iterated multiplication to convert a number
of base into a number of base 10.
We simply add the “contribution” of each digit.
Example: 1F216 = ?10
Number to be converted: ; target base
1F216 = 2 · 160 +
15 · 161 +
1 · 162
= 2 + 240 + 256
⇒ 1F216 = 49810
NB
B N10
N16 1F2= B 10=
Page 20 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Conversions Between Number Systems Prev Next Last
Conversions between Numbers 2n and 2m
• Conversion 2n ⇒ 21
n = 3: octal ⇒ dual:
Replace 1 octal digit by 3 binary digits.
Example: 3 5 78 = 011 101 1112
n = 4: hexadecimal ⇒ dual
Replace 1 hexadecimal digit by 4 binary digits.
Example: 1 F 216 = 0001 1111 00102
Page 21 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Conversions Between Number Systems Prev Next Last
• Conversion 21 ⇒ 2n
n = 3: dual ⇒ octal:
Replace 3 binary digits by 1 octal digit.
Example: 1011110102 = 101 111 0102
= 5 7 28
n = 4: hexadecimal ⇒ dual
Replace 4 binary digits by 1 hexadecimal digit.
Example: 110001111100102 = 11 0001 1111 00102
= 3 1 F 216
Page 22 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Conversions Between Number Systems Prev Next Last
• Conversion 2n ⇒ 2m
2n ⇒ 21 ⇒ 2m
Example: octal ⇒ hexadecimal
263518 = 2 6 3 5 18
octal to binary: = 010 110 011 101 0012
rearrange binary: = 0010 1100 1110 10012
= 2 C E 916
Page 23 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Conversions Between Number Systems Prev Next Last
4.4.2 Conversion of Rational Numbers
Note: An exact conversion of rational numbers ⇒ or ⇒
is not always possible.
• We want: , where is a “sufficiently” small number.
Base B ⇒ Base 10 Conversion
Example: 0.110012 = ?10
0.11001 = 1 · 2-1 + 1 · 2-2 + 0 · 2-3 + 0 · 2-4 + 1 · 2-5
= 1 · 0.5 + 1 · 0.25 + 0 · 0.125 + 0 · 0.0625 + 1 · 0.03125
= 0.5 + 0.25 + 0.03125
= 0.7812510
R10 RB RB
R10
R10 RB ε+= ε
Page 24 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Conversions Between Number Systems Prev Next Last
Base 10 ⇒ Base B Conversion
Example: 0.1910 = ?2 with k = 9 bit precision
⇒ 0.1910 = 0.0011000012 + ε
Step Operation
1 0.19 0.19 · 2 = 0.38 0.38 0
2 0.38 0.38 · 2 = 0.76 0.76 0
3 0.76 0.76 · 2 = 1.52 0.52 1
4 0.52 0.52 · 2 = 1.04 0.04 1
5 0.04 0.04 · 2 = 0.08 0.08 0
6 0.08 0.08 · 2 = 0.16 0.16 0
7 0.16 0.16 · 2 = 0.32 0.32 0
8 0.32 0.32 · 2 = 0.64 0.64 0
9 0.64 0.64 · 2 = 1.28 0.28 1
i N R z i–( )
Multiplication!
Page 25 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Binary Logic Prev Next Last
4.5 Binary Logic
Logical AND ( )
Logical OR ( )
AND 0 1
0 0 0
1 0 1
OR 0 1
0 0 1
1 1 1
x y∧
x y∨
Page 26 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Binary Logic Prev Next Last
Logical NOT ( , negation)
Logical XOR (exclusive OR)
Logical NAND (negated AND)
x
0 1
1 0
XOR 0 1
0 0 1
1 1 0
NAND 0 1
0 1 1
1 1 0
x¬
x¬
Page 27 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Binary Logic Prev Next Last
Examples:
11001010 01000111 11110000
AND 00110101 01110010 10101010
00000000 01000010 10100000
11001010 01000111 11110000
NAND 00110101 01110010 10101010
11111111 10111101 01011111
11001010 01000111 11110000
OR 00110101 01110010 10101010
11111111 01110111 11111010
11001010 01000111 11110000
XOR 00110101 01110010 10101010
11111111 00110101 01011010
Page 28 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Binary Arithmetic Prev Next Last
4.6 Binary Arithmetic
Elementary Rules for addition, subtraction, and multiplication
Operation Result Carry
Addition
0 + 0
0 + 1
1 + 0
1 + 1
0
1
1
0
0
0
0
1
Subtraction
0 - 0
0 - 1
1 - 0
1 - 1
0
1
1
0
0
1
0
0
Multiplication
0 · 0
0 · 1
1 · 0
1 · 1
0
0
0
1
0
0
0
0
Page 29 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Binary Arithmetic Prev Next Last
Examples:
Addition: Subtraction:
1 0 1 0 1 1 0 1
+ 1 0 1 1 - 1 0 1 0
––––––––––––––––- ––––––––––––––––-
carry: 1 0 1 1 carry: 1 0 1 0
+ 1 0 1 1 1 -1 1 1 0
––––––––––––––––- ––––––––––––––––-
1 0 1 0 1 0 0 1 1
1010 1310
+ 1110 - 1010
––––––––––––––––- ––––––––––––––––-
2110 310
Page 30 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Binary Arithmetic Prev Next Last
Multiplication:
1 1 1 · 1 0 1
––––––––––––––––––––––––
1 1 1
0 0 0
+ 1 1 1
––––––––––––––––––––––––
carry: 1
+ 1
carry: 1
+ 1
carry: 1
+ 1
––––––––––––––––––––––––
1 0 0 0 1 1
Page 31 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Negative Numbers and Complements Prev Next Last
4.7 Negative Numbers and Complements
Integer Numbers: A possible representation
Number = sign & value
• sign = 0 ⇒ +, positive number
• sign = 1 ⇒ -, negative number
Range of integer numbers for n bits: - 2n-1+1 … 2n-1-1
15 14 1 0
sign value
Page 32 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Negative Numbers and Complements Prev Next Last
Example (1): n = 3
Range: - 23-1+1 … 23-1-1
= - 22+1 … 22-1
= - 4 + 1 … 4 -1 = -3 ... +3
Sign Value Number
0 0 0 0
0 0 1 1
0 1 0 2
0 1 1 3
1 0 0 ?
1 0 1 - 1
1 1 0 - 2
1 1 1 - 3
Negative zero?
Page 33 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Negative Numbers and Complements Prev Next Last
4.7.1 Problems of Signed Number Representation
• Given 2 binary numbers: one positive, one negative
0 0 1 1 0 0 (base 2) 12 (base 10)
+ 1 0 1 1 1 1 -15
––––––––––––––– ––––––
1 1 1 0 1 1 (= -2710) -3
• “1-1”: 1 - 1 = 1 + (-1) = 0 ?
0 0 0 1 0 0 1
+ 1 0 0 1 - 0 0 1
–––––––––––– –––––––––
1 0 1 0 (= -210) 0 0 0
Clearly this won´t work!
Solution: 1-Complement and 2-Complement
Page 34 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Negative Numbers and Complements Prev Next Last
4.7.2 1-Complement ((B-1)-Complement)
We represent negative numbers by negating the positive
representation of the number (and vice versa):
• any 1 is changed to a 0
• any 0 is changed to a 1
Example:
Binary Decimal One´s Complement Decimal
0 1001 9 1 0110 - 9
1 1001 -6 0 0110 + 6
0 0000 0 1 1111 -15
0 1111 15 1 0000 ?
Problem!
Page 35 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Negative Numbers and Complements Prev Next Last
4.7.3 2-Complement (B-Complement)
• Positive numbers are represented as usual.
• Negative numbers are created by
- negating the positive value and
- adding one (this avoids the negative zero).
Examples:
Binary Decimal Two´s Complement Decimal
0 1001 9 1 0110 + 1 = 1 0111 -9
0 1101 3 1 0010 + 1 = 1 0011 -3
0 0000 0 1 1111 + 1 = 0 0000 0
0 1111 15 1 0000 + 1 = 1 0001 -15
1 1111 -1 ¬(1 1111 - 1) =
¬(1 1110) = 0 0001
1
1 0110 -10 0 1010 10
Page 36 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Negative Numbers and Complements Prev Next Last
Number ring for 5-digit 2-complement
00000
00001
000100001100100
00101
00110
00111
11000
10111
10110
10101
101001001110010
10001
11111
11110
11101
11100
1101111010
11001
10000
1
2
3
4
5
6
7
8
9
10
11
12
13
1415
16
-16
positive
numbers
negative
numbers
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
-11
-12
-13
-14-15
31
30
29
28
27
26
25
24
23
22
21
20
19
18 17
01000
01001
0101001011
01100
01101
01110
01111
SubtractionAddition
Page 37 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Negative Numbers and Complements Prev Next Last
With the 2-complement, subtractions can be performed as simple
additions:
Example: 5 digit precision, base 10
Example 1 Example 2
B = 10 1410 - 710 910 - 1310
Complement 7: 00111
(-7)B-1: 11000
+ 1
–––––––
(-7)B: 11001
13: 01101
(-13)B-1: 10010
+ 1
–––––––
(-13)B: 10011
Addition 14: 01110
+(-7)B: + 11001
–––––––––
7: 1 00111
9: 01001
+(-13)B: + 10011
–––––––––
-4: 11100
Page 38 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Floating Point Numbers Prev Next Last
4.8 Floating Point Numbers
4.8.1 Mantissa and Exponent
Recall the general form of numbers expressed in scientific notation:
• 3.141592653589793238462643383279502884197
• 6.02 x 1023
Printed out by a computer these numbers usually look like this:
• 3.1415e0
• 6.02e23
This representation saves space and reduces redundancy.
Hence, the usual format for a 32-bit real (floating point) number is:
mantissa = 21 bits exponent = 11 bits
Page 39 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Floating Point Numbers Prev Next Last
4.8.2 Floating Point Arithmetics
Example: 0.740 · 105 + 0.843 · 103
Addition:
• 1. Identify mantissae and exponents
• 2. Compare exponents
• 3. Adjust exponents if necessary
• 4. Adjust the shorter mantissa
• 5. Add mantissae
• 6. Normalize mantissa
• 7. Adjust exponent
Operands Compare Exponents Adjust Exponents and Mantissae
0.740 · 105
0.843 · 103 e1 - e2 = 2
0.740 · 105
+ 0.008 · 105
Result: 0.748 · 105
Page 40 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Floating Point Numbers Prev Next Last
Example: Multiplication
• 1. Multiply of mantissae
• 2. Normalize mantissae
• 3. Adjust exponents
• 4. Add exponents
Example: (0.792 · 105) · (0.116 · 10-3)
• Step 1: multiplication of the mantissae:
0.792 · 0.116 =
0.792 · 10-1
+ 0.792 · 10-2
+ 4.752 · 10-3
Page 41 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Floating Point Numbers Prev Next Last
• Step 1 (cont.): step-by-step multiplication of the mantissae
0.792 · 10-1 0.792 · 10-1
0.871 · 10-1
+ 0.792 · 10-2 0.079 · 10-1
0.918 · 10-1
+ 0.4752 · 10-2 0.047 · 10-1
• Step 2:
5 + (-3) + (-1) = 1
• Result:
0.918 · 101 (with 3 digits of precision in the mantissa)
• Step 1 (cont.): step-by-step multiplication of the mantissae
0.792 · 10-1 0.792 · 10-1
0.871 · 10-1
+ 0.792 · 10-2 0.079 · 10-1
0.918 · 10-1
+ 0.4752 · 10-2 0.047 · 10-1
Step 2: Add exponents
5 + (-3) + (-1) = 1
• Result:
0.918 · 101 (with 3 digits of precision)
Page 42 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Floating Point Numbers Prev Next Last
4.8.3 Limited Precision
Note: Not all values can be represented!
Example:
- mantissa: 2 decimal digits
- exponent: 1 decimal digit
• Sample number: 74 · 102 = 7400
What is the next higher value?
75 · 102 = 7500
What about values 7400 < x < 7500?
⇒ They cannot be represented!!!
• Remedy, but not a perfect solution:
Increase the number of mantissa digits.
Page 43 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Representation of Strings Prev Next Last
4.9 Representation of Strings
4.9.1 Representation of Characters
Usually: single characters are represented by 1 byte
different standards: ASCII1, EBCDIC2
Currently: internationalization with Unicode
a single character is represented by 2 bytes
1. ASCII: American Standard Code for Information Interchange
2. EBCDIC: Extended Binary Coded Decimal Interchange Code (derived from punch card standards)
Page 44 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Representation of Strings Prev Next Last
ASCII Character Encoding
Compare the Unicode character encodings …
D C D C D C D C D C D C D C D C
0 NUL 16 DLE 32 SP 48 0 64 @ 80 P 96 ‘ 112 p
1 SCH 17 DC1 33 ! 49 1 65 A 81 Q 97 a 113 q
2 STX 18 DC2 34 “ 50 2 66 B 82 R 98 b 114 r
3 ETX 19 DC3 35 # 51 3 67 C 83 S 99 c 115 s
4 EOT 20 DC4 36 $ 52 4 68 D 84 T 100 d 116 t
5 ENQ 21 NAK 37 % 53 5 69 E 85 U 101 e 117 u
6 ACK 22 SYN 38 & 54 6 70 F 86 V 102 f 118 v
7 BEL 23 ETB 39 ´ 55 7 71 G 87 W 103 g 119 w
8 BS 24 CAN 40 ( 56 8 72 H 88 X 104 h 120 x
9 HT 25 EM 41 ) 57 9 73 I 89 Y 105 i 121 y
10 LF 26 SUB 42 * 58 : 74 J 90 Z 106 j 122 z
11 VT 27 ESC 43 + 59 ; 75 K 91 [ 107 k 123 {
12 FF 28 FS 44 , 60 < 76 L 92  108 l 124 |
13 CR 29 GS 45 - 61 = 77 M 93 ] 109 m 125 }
14 S0 30 RS 46 . 62 > 78 N 94 ^ 110 n 126 ~
15 S1 31 US 47 / 63 ? 79 O 95 _ 111 o 127 DEL
Page 45 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Representation of Strings Prev Next Last
4.10 Representation of Strings
Strings are represented by sequences of characters (⇒ usually: byte
sequence)
1. Fixed length strings (example: length = 7)
2. Variable length strings
3. Encoding with string length at the beginning
1
P
2
e
3
t
4
e
5
r
6
SP
7
SP
1
C
2
o
3
m
4
p
5
u
6
t
7
e r
1
P
2
e
3
t
4
e
5
r
6
NUL
7 n-1 n
2
P
3
e
4
t
5
e
6
r
7 8 n-1 n1
5
Page 46 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob
First Back TOC Representation of Strings Prev Next Last
With ASCII charcter encoding string comparisons are possible:
´AA´ < ´AD´ because: 101 1018 < 101 1048
´AA´ < ´Aa´ 101 1018 < 101 1418
´A1´ < ´AA´ 101 0618 < 101 1018
Hence, sorting of strings becomes easy:
⇒ Compare their numerical representations!

More Related Content

What's hot (17)

Conversion of Number Systems
Conversion of Number SystemsConversion of Number Systems
Conversion of Number Systems
 
Number Systems
Number SystemsNumber Systems
Number Systems
 
Binary number systems
Binary number systemsBinary number systems
Binary number systems
 
Number System
Number SystemNumber System
Number System
 
01.number systems
01.number systems01.number systems
01.number systems
 
Number systems
Number systemsNumber systems
Number systems
 
01.number systems
01.number systems01.number systems
01.number systems
 
Data representation moris mano ch 03
Data representation   moris mano ch  03Data representation   moris mano ch  03
Data representation moris mano ch 03
 
Computer Number system
Computer Number systemComputer Number system
Computer Number system
 
01 intro
01 intro01 intro
01 intro
 
Computer number systems
Computer number systemsComputer number systems
Computer number systems
 
01.Number Systems
01.Number Systems01.Number Systems
01.Number Systems
 
Number+system (1)
Number+system (1)Number+system (1)
Number+system (1)
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Number Systems
Number SystemsNumber Systems
Number Systems
 
Logic Circuits Design - "Chapter 1: Digital Systems and Information"
Logic Circuits Design - "Chapter 1: Digital Systems and Information"Logic Circuits Design - "Chapter 1: Digital Systems and Information"
Logic Circuits Design - "Chapter 1: Digital Systems and Information"
 
digital logic design number system
digital logic design number systemdigital logic design number system
digital logic design number system
 

Viewers also liked

Binary Arithmetic Presentation about Binary Numbers 2015
Binary Arithmetic Presentation about Binary Numbers 2015Binary Arithmetic Presentation about Binary Numbers 2015
Binary Arithmetic Presentation about Binary Numbers 2015An Ariyan
 
Number system utm notes
Number system utm notesNumber system utm notes
Number system utm notesKurenai Ryu
 
binary arithmetic rules
binary arithmetic rulesbinary arithmetic rules
binary arithmetic rulesstudent
 
Area Efficient 4-Bit Full Adder Design using CMOS 90 nm Technology
Area Efficient 4-Bit Full Adder Design using CMOS 90 nm Technology Area Efficient 4-Bit Full Adder Design using CMOS 90 nm Technology
Area Efficient 4-Bit Full Adder Design using CMOS 90 nm Technology IJEEE
 
A high speed dynamic ripple carry adder
A high speed dynamic ripple carry adderA high speed dynamic ripple carry adder
A high speed dynamic ripple carry addereSAT Journals
 
Implementation of Area Effective Carry Select Adders
Implementation of Area Effective Carry Select AddersImplementation of Area Effective Carry Select Adders
Implementation of Area Effective Carry Select AddersKumar Goud
 
Design and Analysis of a Conventional Wallace Multiplier in 180nm CMOS Techno...
Design and Analysis of a Conventional Wallace Multiplier in 180nm CMOS Techno...Design and Analysis of a Conventional Wallace Multiplier in 180nm CMOS Techno...
Design and Analysis of a Conventional Wallace Multiplier in 180nm CMOS Techno...iosrjce
 
High Speed Carryselect Adder
High Speed Carryselect AdderHigh Speed Carryselect Adder
High Speed Carryselect Adderijsrd.com
 
VLSI Implementation of Vedic Multiplier Using Urdhva– Tiryakbhyam Sutra in VH...
VLSI Implementation of Vedic Multiplier Using Urdhva– Tiryakbhyam Sutra in VH...VLSI Implementation of Vedic Multiplier Using Urdhva– Tiryakbhyam Sutra in VH...
VLSI Implementation of Vedic Multiplier Using Urdhva– Tiryakbhyam Sutra in VH...iosrjce
 
CSEC Information Technology Past Papers
CSEC Information Technology Past PapersCSEC Information Technology Past Papers
CSEC Information Technology Past PapersRaymond Douglas
 
Data manipulation instructions
Data manipulation instructionsData manipulation instructions
Data manipulation instructionsMahesh Kumar Attri
 
design of high speed performance 64bit mac unit
design of high speed performance 64bit mac unitdesign of high speed performance 64bit mac unit
design of high speed performance 64bit mac unitShiva Narayan Reddy
 
Success in Creative Writing Exams
Success in Creative Writing ExamsSuccess in Creative Writing Exams
Success in Creative Writing ExamsSian Ferguson
 

Viewers also liked (20)

Binary Arithmetic Presentation about Binary Numbers 2015
Binary Arithmetic Presentation about Binary Numbers 2015Binary Arithmetic Presentation about Binary Numbers 2015
Binary Arithmetic Presentation about Binary Numbers 2015
 
Binary arithmetic
Binary arithmeticBinary arithmetic
Binary arithmetic
 
Number system utm notes
Number system utm notesNumber system utm notes
Number system utm notes
 
binary arithmetic rules
binary arithmetic rulesbinary arithmetic rules
binary arithmetic rules
 
Number system
Number systemNumber system
Number system
 
Area Efficient 4-Bit Full Adder Design using CMOS 90 nm Technology
Area Efficient 4-Bit Full Adder Design using CMOS 90 nm Technology Area Efficient 4-Bit Full Adder Design using CMOS 90 nm Technology
Area Efficient 4-Bit Full Adder Design using CMOS 90 nm Technology
 
A high speed dynamic ripple carry adder
A high speed dynamic ripple carry adderA high speed dynamic ripple carry adder
A high speed dynamic ripple carry adder
 
1 5
1 51 5
1 5
 
Implementation of Area Effective Carry Select Adders
Implementation of Area Effective Carry Select AddersImplementation of Area Effective Carry Select Adders
Implementation of Area Effective Carry Select Adders
 
Design and Analysis of a Conventional Wallace Multiplier in 180nm CMOS Techno...
Design and Analysis of a Conventional Wallace Multiplier in 180nm CMOS Techno...Design and Analysis of a Conventional Wallace Multiplier in 180nm CMOS Techno...
Design and Analysis of a Conventional Wallace Multiplier in 180nm CMOS Techno...
 
High Speed Carryselect Adder
High Speed Carryselect AdderHigh Speed Carryselect Adder
High Speed Carryselect Adder
 
Quantitative Analysis 2
Quantitative Analysis 2Quantitative Analysis 2
Quantitative Analysis 2
 
Unicode
UnicodeUnicode
Unicode
 
VLSI Implementation of Vedic Multiplier Using Urdhva– Tiryakbhyam Sutra in VH...
VLSI Implementation of Vedic Multiplier Using Urdhva– Tiryakbhyam Sutra in VH...VLSI Implementation of Vedic Multiplier Using Urdhva– Tiryakbhyam Sutra in VH...
VLSI Implementation of Vedic Multiplier Using Urdhva– Tiryakbhyam Sutra in VH...
 
Unicode
UnicodeUnicode
Unicode
 
Binary system
Binary systemBinary system
Binary system
 
CSEC Information Technology Past Papers
CSEC Information Technology Past PapersCSEC Information Technology Past Papers
CSEC Information Technology Past Papers
 
Data manipulation instructions
Data manipulation instructionsData manipulation instructions
Data manipulation instructions
 
design of high speed performance 64bit mac unit
design of high speed performance 64bit mac unitdesign of high speed performance 64bit mac unit
design of high speed performance 64bit mac unit
 
Success in Creative Writing Exams
Success in Creative Writing ExamsSuccess in Creative Writing Exams
Success in Creative Writing Exams
 

Similar to 04 bits andarithmetic

Similar to 04 bits andarithmetic (20)

Course Name: Digital System Design Number System.pdf
Course Name: Digital System Design Number System.pdfCourse Name: Digital System Design Number System.pdf
Course Name: Digital System Design Number System.pdf
 
Chapter 1 digital design.pptx
Chapter 1 digital design.pptxChapter 1 digital design.pptx
Chapter 1 digital design.pptx
 
SD & D Representing Positive Numbers
SD & D Representing Positive NumbersSD & D Representing Positive Numbers
SD & D Representing Positive Numbers
 
Number systems and conversions
Number systems and conversionsNumber systems and conversions
Number systems and conversions
 
Lec 02
Lec 02Lec 02
Lec 02
 
Number Systems - AK.pptx
Number Systems - AK.pptxNumber Systems - AK.pptx
Number Systems - AK.pptx
 
Digital Logic Design.pptx
Digital Logic Design.pptxDigital Logic Design.pptx
Digital Logic Design.pptx
 
Module 4
Module 4Module 4
Module 4
 
Digital Electronics Notes.pdf
Digital Electronics Notes.pdfDigital Electronics Notes.pdf
Digital Electronics Notes.pdf
 
Number system
Number systemNumber system
Number system
 
Conversion between number system, part-II
Conversion between number system, part-IIConversion between number system, part-II
Conversion between number system, part-II
 
Conversion between number system, part-I
Conversion between number system, part-IConversion between number system, part-I
Conversion between number system, part-I
 
Representation of Positive Numbers
Representation of Positive NumbersRepresentation of Positive Numbers
Representation of Positive Numbers
 
Unit 4.docx
Unit 4.docxUnit 4.docx
Unit 4.docx
 
5871320.ppt
5871320.ppt5871320.ppt
5871320.ppt
 
More on number system
More on number systemMore on number system
More on number system
 
DCF QNA edited
DCF QNA editedDCF QNA edited
DCF QNA edited
 
Number systems r002
Number systems  r002Number systems  r002
Number systems r002
 
W 9 numbering system
W 9 numbering systemW 9 numbering system
W 9 numbering system
 
DLD-Introduction.pptx
DLD-Introduction.pptxDLD-Introduction.pptx
DLD-Introduction.pptx
 

More from temkin abdlkader (20)

Steel and effect of alloying elements
Steel and effect of alloying elementsSteel and effect of alloying elements
Steel and effect of alloying elements
 
Production of iron and steel
Production of iron and steelProduction of iron and steel
Production of iron and steel
 
Power piont ch2 phase-transformation-in-metals (1)
Power piont   ch2 phase-transformation-in-metals (1)Power piont   ch2 phase-transformation-in-metals (1)
Power piont ch2 phase-transformation-in-metals (1)
 
Phase transformation
Phase transformationPhase transformation
Phase transformation
 
Ironcarbondia
IroncarbondiaIroncarbondia
Ironcarbondia
 
Heat treatment
Heat treatmentHeat treatment
Heat treatment
 
iron carbon phase diagram
iron carbon  phase diagramiron carbon  phase diagram
iron carbon phase diagram
 
Cast irons
Cast  ironsCast  irons
Cast irons
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Workshop1
Workshop1Workshop1
Workshop1
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
Dd3.15 thru-3.21-advanced-functions
Dd3.15 thru-3.21-advanced-functionsDd3.15 thru-3.21-advanced-functions
Dd3.15 thru-3.21-advanced-functions
 
Intro logic ch 4 categorical syllogism
Intro logic ch 4 categorical syllogismIntro logic ch 4 categorical syllogism
Intro logic ch 4 categorical syllogism
 
Intro logic ch 3 doc
Intro logic ch 3 docIntro logic ch 3 doc
Intro logic ch 3 doc
 
Intro logic chaps 6 and 7
Intro logic chaps 6 and 7Intro logic chaps 6 and 7
Intro logic chaps 6 and 7
 
Intro logic ch 4 categorical propositions
Intro logic ch 4 categorical propositionsIntro logic ch 4 categorical propositions
Intro logic ch 4 categorical propositions
 
Paragraph
ParagraphParagraph
Paragraph
 
Essay
Essay Essay
Essay
 
Intro logic ch 2
Intro logic ch 2Intro logic ch 2
Intro logic ch 2
 
Intro logicnote ch 1
Intro logicnote ch 1Intro logicnote ch 1
Intro logicnote ch 1
 

Recently uploaded

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

04 bits andarithmetic

  • 1. © Christian Jacob Chapter Overview Chapter 4 Binary Data Representation and Binary Arithmetic 4.1 Binary Data Representation 4.2 Important Number Systems for Computers 4.2.1 Number System Basics 4.2.2 Useful Number Systems for Computers 4.2.3 Decimal Number System 4.2.4 Binary Number System 4.2.5 Octal Number System 4.2.6 Hexadecimal Number System 4.2.7 Comparison of Number Systems 4.3 Powers of 2
  • 2. © Christian Jacob Chapter Overview 4.4 Conversions Between Number Systems 4.4.1 Conversion of Natural Numbers 4.4.2 Conversion of Rational Numbers 4.5 Binary Logic 4.6 Binary Arithmetic 4.7 Negative Numbers and Complements 4.7.1 Problems of Signed Number Representation 4.7.2 1-Complement ((B-1)-Complement) 4.7.3 2-Complement (B-Complement) 4.8 Floating Point Numbers 4.8.1 Mantissa and Exponent 4.8.2 Floating Point Arithmetics 4.8.3 Limited Precision 4.9 Representation of Strings 4.9.1 Representation of Characters 4.9.2 Representation of Strings
  • 3. Page 3 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Prev Next Last 4.1 Binary Data Representation Bit: smallest unit of information yes / no, on / off, L / 0, 1 / 0, 5V / 0V Byte: group of 8 bits --> 28 = 256 different states Word: the number of bits (word length) which can be processed by a computer in a single step (e.g., 32 or 64) --> machine dependent Representation: n-1 2n-1 3 8 2 4 1 2 0 1 . . .
  • 4. Page 4 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Prev Next Last • The word size in any given computer is fixed. Example: 16-bit word ⇒ every word (memory location) can hold a 16-bit pattern, with each bit either 0 or 1. How many distinct patterns are there in a 16-bit word? • Each bit has 2 possible values: 0 or 1 ⇒ 1 bit has 2 distinct patterns: 0, 1 • With 2 bits, each position has 2 possible values: 00, 01, 10, 11 ⇒ 22 = 4 distinct bit patterns
  • 5. Page 5 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Prev Next Last • With 3 bits, again each position can be either 0 or 1: 000 100 001 101 010 110 011 111 ⇒ 23 = 8 distinct bit patterns • In general, for n bits (a word of length n) we have 2n distinct bit patterns. • NOTE: What these bit patterns mean depends entirely on the context in which the patterns are used.
  • 6. Page 6 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Important Number Systems for Computers Prev Next Last 4.2 Important Number Systems for Computers 4.2.1 Number System Basics • Number systems, as we use them, consist of - a basic set of digits (or letters); example: - a base (how many digits); example: • A number is a linear sequence of digits. • The value of a digit at a specific position depends on its “assigned meaning” and on its position. • The value of a number is the sum of these values. Number: with word length Value: Z Z 0 1 2 … 9, , , ,{ }= B Z= B Z 10= = N NB dn 1– dn 2– …d1d0= n NB di B i ⋅ i 0= n 1– ∑ dn 1– B n 1– dn 2– B n 2– … d1B 1 d0B 0 + + + += =
  • 7. Page 7 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Important Number Systems for Computers Prev Next Last 4.2.2 Useful Number Systems for Computers Name Base Digits dual binary 2 0, 1 octal 8 0, 1, 2, 3, 4, 5, 6, 7 decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 hexadecimal sedecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
  • 8. Page 8 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Important Number Systems for Computers Prev Next Last 4.2.3 Decimal Number System ; • Each position to the left of a digit increases by a power of 10. • Each position to the right of a digit decreases by a power of 10. Example: 4769210 = 2 · 100 + 9 · 101 + 6 · 102 + 7 · 103 + 4 · 104 = 2 + 90 + 600 + 7000 + 40000 Z 0 1 2 3 4 5 6 7 8 9, , , , , , , , ,{ }= B 10=
  • 9. Page 9 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Important Number Systems for Computers Prev Next Last 4.2.4 Binary Number System ; • Each position to the left of a digit increases by a power of 2. • Each position to the right of a digit decreases by a power of 2. Example: 101110012 = 1 · 20 + 0 · 21 + 0 · 22 + 1 · 23 + 1 · 24 + 1 · 25 + 0 · 26 + 1 · 27 = 1 + 8 + 16 + 32 + 128 =18510 Z 0 1,{ }= B 2=
  • 10. Page 10 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Important Number Systems for Computers Prev Next Last Counting in Binary Decimal Dual Decimal Dual 0 00 000 16 10 000 1 00 001 17 10 001 2 00 010 18 10 010 3 00 011 19 10 011 4 00 100 20 10 100 5 00 101 21 10 101 6 00 110 22 10 110 7 00 111 23 10 111 8 01 000 24 11 000 9 01 001 25 11 001 10 01 010 26 11 010 11 01 011 27 11 011 12 01 100 28 11 100 13 01 101 29 11 101 14 01 110 30 11 110 15 01 111 31 11 111
  • 11. Page 11 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Important Number Systems for Computers Prev Next Last 4.2.5 Octal Number System ; • Each position to the left of a digit increases by a power of 8. • Each position to the right of a digit decreases by a power of 8. Example: 124038 = 3 · 80 + 0 · 81 + 4 · 82 + 2 · 83 + 1 · 84 = 3 · 1 + 0 · 8 + 4 · 64 + 2 · 512 + 1 · 4096 = 537910 Z 0 1 2 3 4 5 6 7, , , , , , ,{ }= B 8=
  • 12. Page 12 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Important Number Systems for Computers Prev Next Last Counting in Octal Decimal Octal Decimal Octal 0 0 0 16 2 0 1 0 1 17 2 1 2 0 2 18 2 2 3 0 3 19 2 3 4 0 4 20 2 4 5 0 5 21 2 5 6 0 6 22 2 6 7 0 7 23 2 7 8 1 0 24 3 0 9 1 1 25 3 1 10 1 2 26 3 2 11 1 3 27 3 3 12 1 4 28 3 4 13 1 5 29 3 5 14 1 6 30 3 6 15 1 7 31 3 7
  • 13. Page 13 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Important Number Systems for Computers Prev Next Last 4.2.6 Hexadecimal Number System ; Each position to the left of a digit increases by a power of 16. Each position to the right of a digit decreases by a power of 16. Example: FB40A16 = 10 · 160 + 0 · 161 + 4 · 162 + 11 · 163 + 15 · 164 = 10 · 1 + 0 · 16 + 4 · 256 + 11 · 4096 + 15 · 65536 = 1,029,13010 Z 0 1 2 3 4 5 6 7 8 9 A B C D E F, , , , , , , , , , , , , , ,{ }= B 16=
  • 14. Page 14 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Important Number Systems for Computers Prev Next Last Counting in Hexadecimal Decimal Hexadecimal Decimal Hexadecimal 0 0 0 16 1 0 1 0 1 17 1 1 2 0 2 18 1 2 3 0 3 19 1 3 4 0 4 20 1 4 5 0 5 21 1 5 6 0 6 22 1 6 7 0 7 23 1 7 8 0 8 24 1 8 9 0 9 25 1 9 10 0 A 26 1 A 11 0 B 27 1 B 12 0 C 28 1 C 13 0 D 29 1 D 14 0 E 30 1 E 15 0 F 31 1 F
  • 15. Page 15 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Important Number Systems for Computers Prev Next Last 4.2.7 Comparison of Number Systems Decimal Dual Octal Hexadecimal Decimal Dual Octal Hexadecimal 0 00 000 0 0 0 0 16 10 000 2 0 1 0 1 00 001 0 1 0 1 17 10 001 2 1 1 1 2 00 010 0 2 0 2 18 10 010 2 2 1 2 3 00 011 0 3 0 3 19 10 011 2 3 1 3 4 00 100 0 4 0 4 20 10 100 2 4 1 4 5 00 101 0 5 0 5 21 10 101 2 5 1 5 6 00 110 0 6 0 6 22 10 110 2 6 1 6 7 00 111 0 7 0 7 23 10 111 2 7 1 7 8 01 000 1 0 0 8 24 11 000 3 0 1 8 9 01 001 1 1 0 9 25 11 001 3 1 1 9 10 01 010 1 2 0 A 26 11 010 3 2 1 A 11 01 011 1 3 0 B 27 11 011 3 3 1 B 12 01 100 1 4 0 C 28 11 100 3 4 1 C 13 01 101 1 5 0 D 29 11 101 3 5 1 D 14 01 110 1 6 0 E 30 11 110 3 6 1 E 15 01 111 1 7 0 F 31 11 111 3 7 1 F
  • 16. Page 16 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Powers of 2 Prev Next Last 4.3 Powers of 2 N 2N N 2N 0 1 17 131,072 1 2 18 262,144 2 4 19 524,288 3 8 20 1,048,576 4 16 21 2,097,152 5 32 22 4,194,304 6 64 23 8,388,608 7 128 24 16,777,216 8 256 25 33,554,432 9 512 26 67,108,864 10 1,024 27 134,217,728 11 2,048 28 268,435,456 12 4,096 29 536,870,912 13 8,192 30 1,073,741,824 14 16,384 31 2,147,483,648 15 32,768 32 4,294,967,296 16 65,536 33 8,589,934,592
  • 17. Page 17 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Conversions Between Number Systems Prev Next Last 4.4 Conversions Between Number Systems 4.4.1 Conversion of Natural Numbers Base 10 ⇒ Base B Conversion We use the metod of iterated division to convert a number of base 10 into a number of base . 1. Divide the number by : whole number & remainder . - Take as the next number to be divided by . - Keep as the next left-most digit of the new number . 2. If is zero then STOP, else set and go to step 1. N10 NB B N10 B N R N B R NB N N10 N=
  • 18. Page 18 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Conversions Between Number Systems Prev Next Last Example: 102010 = ? 8 Number to be converted: ; target base Step 1: 1020 : 8 = 127 Remainder: 4 127 · 8 = 1016 Step 2: 127 : 8 = 15 Remainder: 7 15 · 8 = 120 Step 3: 15 : 8 = 1 Remainder: 7 1 · 8 = 8 Step 4: 1 : 8 = 0 Remainder: 1 ⇒ 102010 = 17748 N10 1020= B 8=
  • 19. Page 19 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Conversions Between Number Systems Prev Next Last Base B ⇒ Base 10 Conversion We use the metod of iterated multiplication to convert a number of base into a number of base 10. We simply add the “contribution” of each digit. Example: 1F216 = ?10 Number to be converted: ; target base 1F216 = 2 · 160 + 15 · 161 + 1 · 162 = 2 + 240 + 256 ⇒ 1F216 = 49810 NB B N10 N16 1F2= B 10=
  • 20. Page 20 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Conversions Between Number Systems Prev Next Last Conversions between Numbers 2n and 2m • Conversion 2n ⇒ 21 n = 3: octal ⇒ dual: Replace 1 octal digit by 3 binary digits. Example: 3 5 78 = 011 101 1112 n = 4: hexadecimal ⇒ dual Replace 1 hexadecimal digit by 4 binary digits. Example: 1 F 216 = 0001 1111 00102
  • 21. Page 21 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Conversions Between Number Systems Prev Next Last • Conversion 21 ⇒ 2n n = 3: dual ⇒ octal: Replace 3 binary digits by 1 octal digit. Example: 1011110102 = 101 111 0102 = 5 7 28 n = 4: hexadecimal ⇒ dual Replace 4 binary digits by 1 hexadecimal digit. Example: 110001111100102 = 11 0001 1111 00102 = 3 1 F 216
  • 22. Page 22 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Conversions Between Number Systems Prev Next Last • Conversion 2n ⇒ 2m 2n ⇒ 21 ⇒ 2m Example: octal ⇒ hexadecimal 263518 = 2 6 3 5 18 octal to binary: = 010 110 011 101 0012 rearrange binary: = 0010 1100 1110 10012 = 2 C E 916
  • 23. Page 23 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Conversions Between Number Systems Prev Next Last 4.4.2 Conversion of Rational Numbers Note: An exact conversion of rational numbers ⇒ or ⇒ is not always possible. • We want: , where is a “sufficiently” small number. Base B ⇒ Base 10 Conversion Example: 0.110012 = ?10 0.11001 = 1 · 2-1 + 1 · 2-2 + 0 · 2-3 + 0 · 2-4 + 1 · 2-5 = 1 · 0.5 + 1 · 0.25 + 0 · 0.125 + 0 · 0.0625 + 1 · 0.03125 = 0.5 + 0.25 + 0.03125 = 0.7812510 R10 RB RB R10 R10 RB ε+= ε
  • 24. Page 24 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Conversions Between Number Systems Prev Next Last Base 10 ⇒ Base B Conversion Example: 0.1910 = ?2 with k = 9 bit precision ⇒ 0.1910 = 0.0011000012 + ε Step Operation 1 0.19 0.19 · 2 = 0.38 0.38 0 2 0.38 0.38 · 2 = 0.76 0.76 0 3 0.76 0.76 · 2 = 1.52 0.52 1 4 0.52 0.52 · 2 = 1.04 0.04 1 5 0.04 0.04 · 2 = 0.08 0.08 0 6 0.08 0.08 · 2 = 0.16 0.16 0 7 0.16 0.16 · 2 = 0.32 0.32 0 8 0.32 0.32 · 2 = 0.64 0.64 0 9 0.64 0.64 · 2 = 1.28 0.28 1 i N R z i–( ) Multiplication!
  • 25. Page 25 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Binary Logic Prev Next Last 4.5 Binary Logic Logical AND ( ) Logical OR ( ) AND 0 1 0 0 0 1 0 1 OR 0 1 0 0 1 1 1 1 x y∧ x y∨
  • 26. Page 26 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Binary Logic Prev Next Last Logical NOT ( , negation) Logical XOR (exclusive OR) Logical NAND (negated AND) x 0 1 1 0 XOR 0 1 0 0 1 1 1 0 NAND 0 1 0 1 1 1 1 0 x¬ x¬
  • 27. Page 27 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Binary Logic Prev Next Last Examples: 11001010 01000111 11110000 AND 00110101 01110010 10101010 00000000 01000010 10100000 11001010 01000111 11110000 NAND 00110101 01110010 10101010 11111111 10111101 01011111 11001010 01000111 11110000 OR 00110101 01110010 10101010 11111111 01110111 11111010 11001010 01000111 11110000 XOR 00110101 01110010 10101010 11111111 00110101 01011010
  • 28. Page 28 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Binary Arithmetic Prev Next Last 4.6 Binary Arithmetic Elementary Rules for addition, subtraction, and multiplication Operation Result Carry Addition 0 + 0 0 + 1 1 + 0 1 + 1 0 1 1 0 0 0 0 1 Subtraction 0 - 0 0 - 1 1 - 0 1 - 1 0 1 1 0 0 1 0 0 Multiplication 0 · 0 0 · 1 1 · 0 1 · 1 0 0 0 1 0 0 0 0
  • 29. Page 29 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Binary Arithmetic Prev Next Last Examples: Addition: Subtraction: 1 0 1 0 1 1 0 1 + 1 0 1 1 - 1 0 1 0 ––––––––––––––––- ––––––––––––––––- carry: 1 0 1 1 carry: 1 0 1 0 + 1 0 1 1 1 -1 1 1 0 ––––––––––––––––- ––––––––––––––––- 1 0 1 0 1 0 0 1 1 1010 1310 + 1110 - 1010 ––––––––––––––––- ––––––––––––––––- 2110 310
  • 30. Page 30 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Binary Arithmetic Prev Next Last Multiplication: 1 1 1 · 1 0 1 –––––––––––––––––––––––– 1 1 1 0 0 0 + 1 1 1 –––––––––––––––––––––––– carry: 1 + 1 carry: 1 + 1 carry: 1 + 1 –––––––––––––––––––––––– 1 0 0 0 1 1
  • 31. Page 31 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Negative Numbers and Complements Prev Next Last 4.7 Negative Numbers and Complements Integer Numbers: A possible representation Number = sign & value • sign = 0 ⇒ +, positive number • sign = 1 ⇒ -, negative number Range of integer numbers for n bits: - 2n-1+1 … 2n-1-1 15 14 1 0 sign value
  • 32. Page 32 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Negative Numbers and Complements Prev Next Last Example (1): n = 3 Range: - 23-1+1 … 23-1-1 = - 22+1 … 22-1 = - 4 + 1 … 4 -1 = -3 ... +3 Sign Value Number 0 0 0 0 0 0 1 1 0 1 0 2 0 1 1 3 1 0 0 ? 1 0 1 - 1 1 1 0 - 2 1 1 1 - 3 Negative zero?
  • 33. Page 33 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Negative Numbers and Complements Prev Next Last 4.7.1 Problems of Signed Number Representation • Given 2 binary numbers: one positive, one negative 0 0 1 1 0 0 (base 2) 12 (base 10) + 1 0 1 1 1 1 -15 ––––––––––––––– –––––– 1 1 1 0 1 1 (= -2710) -3 • “1-1”: 1 - 1 = 1 + (-1) = 0 ? 0 0 0 1 0 0 1 + 1 0 0 1 - 0 0 1 –––––––––––– ––––––––– 1 0 1 0 (= -210) 0 0 0 Clearly this won´t work! Solution: 1-Complement and 2-Complement
  • 34. Page 34 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Negative Numbers and Complements Prev Next Last 4.7.2 1-Complement ((B-1)-Complement) We represent negative numbers by negating the positive representation of the number (and vice versa): • any 1 is changed to a 0 • any 0 is changed to a 1 Example: Binary Decimal One´s Complement Decimal 0 1001 9 1 0110 - 9 1 1001 -6 0 0110 + 6 0 0000 0 1 1111 -15 0 1111 15 1 0000 ? Problem!
  • 35. Page 35 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Negative Numbers and Complements Prev Next Last 4.7.3 2-Complement (B-Complement) • Positive numbers are represented as usual. • Negative numbers are created by - negating the positive value and - adding one (this avoids the negative zero). Examples: Binary Decimal Two´s Complement Decimal 0 1001 9 1 0110 + 1 = 1 0111 -9 0 1101 3 1 0010 + 1 = 1 0011 -3 0 0000 0 1 1111 + 1 = 0 0000 0 0 1111 15 1 0000 + 1 = 1 0001 -15 1 1111 -1 ¬(1 1111 - 1) = ¬(1 1110) = 0 0001 1 1 0110 -10 0 1010 10
  • 36. Page 36 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Negative Numbers and Complements Prev Next Last Number ring for 5-digit 2-complement 00000 00001 000100001100100 00101 00110 00111 11000 10111 10110 10101 101001001110010 10001 11111 11110 11101 11100 1101111010 11001 10000 1 2 3 4 5 6 7 8 9 10 11 12 13 1415 16 -16 positive numbers negative numbers 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14-15 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 01000 01001 0101001011 01100 01101 01110 01111 SubtractionAddition
  • 37. Page 37 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Negative Numbers and Complements Prev Next Last With the 2-complement, subtractions can be performed as simple additions: Example: 5 digit precision, base 10 Example 1 Example 2 B = 10 1410 - 710 910 - 1310 Complement 7: 00111 (-7)B-1: 11000 + 1 ––––––– (-7)B: 11001 13: 01101 (-13)B-1: 10010 + 1 ––––––– (-13)B: 10011 Addition 14: 01110 +(-7)B: + 11001 ––––––––– 7: 1 00111 9: 01001 +(-13)B: + 10011 ––––––––– -4: 11100
  • 38. Page 38 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Floating Point Numbers Prev Next Last 4.8 Floating Point Numbers 4.8.1 Mantissa and Exponent Recall the general form of numbers expressed in scientific notation: • 3.141592653589793238462643383279502884197 • 6.02 x 1023 Printed out by a computer these numbers usually look like this: • 3.1415e0 • 6.02e23 This representation saves space and reduces redundancy. Hence, the usual format for a 32-bit real (floating point) number is: mantissa = 21 bits exponent = 11 bits
  • 39. Page 39 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Floating Point Numbers Prev Next Last 4.8.2 Floating Point Arithmetics Example: 0.740 · 105 + 0.843 · 103 Addition: • 1. Identify mantissae and exponents • 2. Compare exponents • 3. Adjust exponents if necessary • 4. Adjust the shorter mantissa • 5. Add mantissae • 6. Normalize mantissa • 7. Adjust exponent Operands Compare Exponents Adjust Exponents and Mantissae 0.740 · 105 0.843 · 103 e1 - e2 = 2 0.740 · 105 + 0.008 · 105 Result: 0.748 · 105
  • 40. Page 40 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Floating Point Numbers Prev Next Last Example: Multiplication • 1. Multiply of mantissae • 2. Normalize mantissae • 3. Adjust exponents • 4. Add exponents Example: (0.792 · 105) · (0.116 · 10-3) • Step 1: multiplication of the mantissae: 0.792 · 0.116 = 0.792 · 10-1 + 0.792 · 10-2 + 4.752 · 10-3
  • 41. Page 41 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Floating Point Numbers Prev Next Last • Step 1 (cont.): step-by-step multiplication of the mantissae 0.792 · 10-1 0.792 · 10-1 0.871 · 10-1 + 0.792 · 10-2 0.079 · 10-1 0.918 · 10-1 + 0.4752 · 10-2 0.047 · 10-1 • Step 2: 5 + (-3) + (-1) = 1 • Result: 0.918 · 101 (with 3 digits of precision in the mantissa) • Step 1 (cont.): step-by-step multiplication of the mantissae 0.792 · 10-1 0.792 · 10-1 0.871 · 10-1 + 0.792 · 10-2 0.079 · 10-1 0.918 · 10-1 + 0.4752 · 10-2 0.047 · 10-1 Step 2: Add exponents 5 + (-3) + (-1) = 1 • Result: 0.918 · 101 (with 3 digits of precision)
  • 42. Page 42 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Floating Point Numbers Prev Next Last 4.8.3 Limited Precision Note: Not all values can be represented! Example: - mantissa: 2 decimal digits - exponent: 1 decimal digit • Sample number: 74 · 102 = 7400 What is the next higher value? 75 · 102 = 7500 What about values 7400 < x < 7500? ⇒ They cannot be represented!!! • Remedy, but not a perfect solution: Increase the number of mantissa digits.
  • 43. Page 43 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Representation of Strings Prev Next Last 4.9 Representation of Strings 4.9.1 Representation of Characters Usually: single characters are represented by 1 byte different standards: ASCII1, EBCDIC2 Currently: internationalization with Unicode a single character is represented by 2 bytes 1. ASCII: American Standard Code for Information Interchange 2. EBCDIC: Extended Binary Coded Decimal Interchange Code (derived from punch card standards)
  • 44. Page 44 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Representation of Strings Prev Next Last ASCII Character Encoding Compare the Unicode character encodings … D C D C D C D C D C D C D C D C 0 NUL 16 DLE 32 SP 48 0 64 @ 80 P 96 ‘ 112 p 1 SCH 17 DC1 33 ! 49 1 65 A 81 Q 97 a 113 q 2 STX 18 DC2 34 “ 50 2 66 B 82 R 98 b 114 r 3 ETX 19 DC3 35 # 51 3 67 C 83 S 99 c 115 s 4 EOT 20 DC4 36 $ 52 4 68 D 84 T 100 d 116 t 5 ENQ 21 NAK 37 % 53 5 69 E 85 U 101 e 117 u 6 ACK 22 SYN 38 & 54 6 70 F 86 V 102 f 118 v 7 BEL 23 ETB 39 ´ 55 7 71 G 87 W 103 g 119 w 8 BS 24 CAN 40 ( 56 8 72 H 88 X 104 h 120 x 9 HT 25 EM 41 ) 57 9 73 I 89 Y 105 i 121 y 10 LF 26 SUB 42 * 58 : 74 J 90 Z 106 j 122 z 11 VT 27 ESC 43 + 59 ; 75 K 91 [ 107 k 123 { 12 FF 28 FS 44 , 60 < 76 L 92 108 l 124 | 13 CR 29 GS 45 - 61 = 77 M 93 ] 109 m 125 } 14 S0 30 RS 46 . 62 > 78 N 94 ^ 110 n 126 ~ 15 S1 31 US 47 / 63 ? 79 O 95 _ 111 o 127 DEL
  • 45. Page 45 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Representation of Strings Prev Next Last 4.10 Representation of Strings Strings are represented by sequences of characters (⇒ usually: byte sequence) 1. Fixed length strings (example: length = 7) 2. Variable length strings 3. Encoding with string length at the beginning 1 P 2 e 3 t 4 e 5 r 6 SP 7 SP 1 C 2 o 3 m 4 p 5 u 6 t 7 e r 1 P 2 e 3 t 4 e 5 r 6 NUL 7 n-1 n 2 P 3 e 4 t 5 e 6 r 7 8 n-1 n1 5
  • 46. Page 46 Chapter 4: Binary Data Representation and Arithmetic © Christian Jacob First Back TOC Representation of Strings Prev Next Last With ASCII charcter encoding string comparisons are possible: ´AA´ < ´AD´ because: 101 1018 < 101 1048 ´AA´ < ´Aa´ 101 1018 < 101 1418 ´A1´ < ´AA´ 101 0618 < 101 1018 Hence, sorting of strings becomes easy: ⇒ Compare their numerical representations!