Lecture 4: Information Representation
Information Representation
Information Representation
Computer use a binary systems
Computer use a binary systems
Why binary?
Why binary?
Electronic bi-stable environment
Electronic bi-stable environment
on/off, high/low voltage
on/off, high/low voltage
Bit: each bit can be either 0 or 1
Bit: each bit can be either 0 or 1
Reliability
Reliability
With only 2 values, can be widely separated, therefore clearly
With only 2 values, can be widely separated, therefore clearly
differentiated
differentiated
“
“drift” causes less error
drift” causes less error
Example:
Example:
-3 mv
0 mv
0 0 0
1
1
1
Digital v.s, Analog
1 0 0 1 0 1 0 1 1 0 0 0 0 0 0 1
Lecture 4: Information Representation
Visit: tshahab.blogspot.com
Visit: tshahab.blogspot.com
• Binary Representation in Computer System
– All information of diverse type is represented within
computers in the form of bit patterns.
• e.g., text, numerical data, sound, and images
– One important aspect of computer design is to decide
how information is converted ultimately to a bit pattern
– Writing software also frequently requires understanding
how information is represented along with accuracies
Lecture 4: Information Representation
Number Systems
Number Systems
Decimal Number System
Decimal Number System
Base is 10 or ‘D’ or ‘Dec’
Ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Each place is weighted by the power of 10
Example:
123410 or 1234D
= 1 x 103
+ 2 x 102
+ 3 x 101
+ 4 x 100
= 1000 + 200 + 30 + 4
$1,000
$100
$10
$1
Lecture 4: Information Representation
Binary Number System
Binary Number System
Base is 2 or ‘b’ or ‘B’ or ‘Bin’
Base is 2 or ‘b’ or ‘B’ or ‘Bin’
Two symbols: 0 and 1
Two symbols: 0 and 1
Each place is weighted by the power of 2
Each place is weighted by the power of 2
Example
Example:
:
1011
10112
2 or
or 1011
1011 B
B
= 1 x
= 1 x 2
23
3
+ 0 x
+ 0 x 2
22
2
+ 1 x
+ 1 x 2
21
1
+ 1 x
+ 1 x 2
20
0
= 8 + 0 + 2 +1
= 8 + 0 + 2 +1
= 11
= 1110
10
11
11 in decimal number system is
in decimal number system is 1011
1011 in binary number system
in binary number system
Lecture 4: Information Representation
Conversion between Decimal and Binary
Conversion between Decimal and Binary
Conversion from decimal number system to binary
Conversion from decimal number system to binary
system
system
Question: represent 3410 in the binary number system
Answer: using the divide-by-2 technique repeatedly
If we write the remainder from right to left :
3410  1 x 25
+ 0 x 24
+ 0 x 23
+ 0 x 22
+ 1x 21
+ 0 x 20
 1000102
34 8
17 2
4 1
0 1 0 0 0 1 Remainder
div-by-2 div-by-2 div-by-2 div-by-2 div-by-2 div-by-2
Lecture 4: Information Representation
Converting decimal to binary
Converting decimal to binary
Example: 162:
Example: 162:
So, 162
So, 16210
10 =
= 10100010
101000102
2
162 / 2 = 81 rem 0
81 / 2 = 40 rem 1
40 / 2 = 20 rem 0
20 / 2 = 10 rem 0
10 / 2 = 5 rem 0
5 / 2 = 2 rem 1
2 / 2 = 1 rem 0
1 / 2 = 0 rem 1
Lecture 4: Information Representation
Some Exercises
Some Exercises
13D = (?) B
23D = (?) B
72D = (?) B
1101
1101B
B
Lecture 4: Information Representation
Conversion from binary number system to
Conversion from binary number system to
decimal system
decimal system
Example: check if 1000102 is 3410
using the :weights” appropriately
1000102  1 x 25
+ 0 x 24
+ 0 x 23
+ 0 x 22
+ 1 x 21
+ 0 x 20
 32 + 0 + 0 + 0 + 2 +
0
 3410
Lecture 4: Information Representation
Some Exercises
Some Exercises
Ex: 0101
Ex: 0101B
B
 ( ? )
( ? ) D
D
Ex: 1100
Ex: 1100B
B 
 ( ? )
( ? ) D
D
Ex: 0101 1100
Ex: 0101 1100B
B 
 ( ? )
( ? ) D
D
Bit 4
23
= 8
Bit 3
22
= 4
Bit 2
21
= 2
Bit 1
20
= 1
0
0 1
1 0
0 1
1
4 1
+ = 5D
1 1 0 0
8 4 2 1 = 12D
0 1 0 1 1 1 0 0
128 64 32 16 8 4 2 1 = 92D
Lecture 4: Information Representation
Binary Arithmetic on Integers
Binary Arithmetic on Integers
Addition
Addition
a b a + b
0 0
0 1
1 0
1 1
13D
+ 5D
18D
15D
+ 10D
25D
0
1
1 0
1
Example: find binary number of a + b
• If a = 13D , b = 5D
• If a = 15D, b = 10D
1 1 1
1 1 0 1b
0 1 0 1b
+
1 1 1
1 1 1 1b
1 0 1 0b
1 1 0 0 1b
+
1 0b
0
0
1
Carry bit
Lecture 4: Information Representation
Multiplication
Multiplication
Binary Arithmetic on Integers
Binary Arithmetic on Integers (cont.)
(cont.)
a b a x b
0 0
0 1
1 0
1 1
1 0 0 0 0 1b
x 1 0 1b
0
1
0
0
 33D
 5D
 165D
1 0 0 0 0 1
0 0 0 0 0 0 0
1 0 0 0 0 1 0 0
1 0 1 0 0 1 0 1b
Example: if a = 100001b , b = 101b , find a x b
Lecture 4: Information Representation
Hexadecimal Number System
Hexadecimal Number System
Hexadecimal Number System
Hexadecimal Number System
Base = 16 or ‘H’ or ‘Hex’
16 symbols:
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A(=10), B(=11), C(=12), D(=13), E(=14), F(=15)}
Hexadecimal to Decimal
Hexadecimal to Decimal
(an-1an-2…a1a0)16 = (an-1 x 16n-1
+ an-2 x 16n-2
+ …+ a1 x 161
+ a0 x 160
)D
Example: (1C7)16 = (1 x 162
+ 12 x 161
+ 7 x 160
)10 = (256 + 192 + 7)10 = (455)10
Decimal to Hexadecimal
Decimal to Hexadecimal Repeated division by 16
Similar in principle to generating binary codes
binary codes
Example
Example: (829)
: (829)10
10 =
= (?
(? )
)16
16
Stop, since quotient = 0
Stop, since quotient = 0
Hence, (829)
Hence, (829)10
10 = (3313)
= (3313)16
16
Divide-by-16 Quotient Remainder
829 / 16
51 / 16
3 / 16
51
3
0
13
3
3
(33D)
(33D)16
16
Lecture 4: Information Representation
Hexadecimal Conversions
Hexadecimal Conversions
Hexadecimal to Binary
Hexadecimal to Binary
Expand each hexadecimal digit to 4 binary bits.
Example: (E29)16 = (1110 | 0010 | 1001)2
Binary to Hexadecimal
Binary to Hexadecimal
Combine every 4 bits into one hexadecimal digit
Example: (0101 | 1111 | 1010 | 0110)2 = (5FA6)16
Lecture 4: Information Representation
Octal Number System
Octal Number System
Octal Number System
Octal Number System
Base = 8 or ‘o’ or ‘Oct’
8 symbols: { 0, 1, 2, 3, 4, 5, 6, 7}
Octal to Decimal
Octal to Decimal
(an-1an-2…a1a0)8 = (an-1 x 8n-1
+ an-2 x 8n-2
+ …+ a1 x 81
+ a0 x 80
)10
Example: (127)8 = (1 x 82
+ 2 x 81
+ 7 x 80
)10 = (64 + 16 + 7)10 = (87)10
Decimal to Octal
Decimal to Octal
Repeated division by 8 (similar in principle to generating binary codes)
Example: (213)10 = (? )8
Stop, since quotient = 0
Stop, since quotient = 0
Hence, (213)
Hence, (213)10
10 = (325)
= (325)8
8
Divide-by -8 Quotient Remainder Octal digit
213 / 8
26 / 8
3 / 8
26
3
0
5
2
3
Lower digit = 5
Second digit =2
Third digit =3
Lecture 4: Information Representation
Octal to Binary
Expand each octal digit to 3 binary bits.
Example: (725)8 = (111 | 010 | 101)2
Binary to Octal
Combine every 3 bits into one octal digit
Example: (110 | 010 | 011)2 = (623)8
Visit: tshahab.blogspot.com
Lecture 4: Information Representation
Mini Homework
Mini Homework
1) Convert the following binary numbers to decimal
numbers:
(a) 0011 B
(b) 0101 B
(c) 0001 0110 B
(d) 0101 0011 B
2) Convert the following decimal numbers to binary:
(a) 21 D
(b) 731 D
(c) 1,023 D
Lecture 4: Information Representation
3) Convert the following binary numbers to hexadecimal
numbers:
(a) 0011 B
(b) 0101 B
(c) 0001 0110 B
(d) 0101 0011 B
(a) 21 D
(b) 731 D
(c) 1,023 D
4.) Perform the following binary additions and subtractions.
Show your work without using decimal numbers during
conversion.
(a) 111 B
+ 101 B
(b) 1001 B
+ 11 B

Infomation & Communication Technology Lecture 4 Information Representation

  • 1.
    Lecture 4: InformationRepresentation Information Representation Information Representation Computer use a binary systems Computer use a binary systems Why binary? Why binary? Electronic bi-stable environment Electronic bi-stable environment on/off, high/low voltage on/off, high/low voltage Bit: each bit can be either 0 or 1 Bit: each bit can be either 0 or 1 Reliability Reliability With only 2 values, can be widely separated, therefore clearly With only 2 values, can be widely separated, therefore clearly differentiated differentiated “ “drift” causes less error drift” causes less error Example: Example: -3 mv 0 mv 0 0 0 1 1 1 Digital v.s, Analog 1 0 0 1 0 1 0 1 1 0 0 0 0 0 0 1
  • 2.
    Lecture 4: InformationRepresentation Visit: tshahab.blogspot.com Visit: tshahab.blogspot.com • Binary Representation in Computer System – All information of diverse type is represented within computers in the form of bit patterns. • e.g., text, numerical data, sound, and images – One important aspect of computer design is to decide how information is converted ultimately to a bit pattern – Writing software also frequently requires understanding how information is represented along with accuracies
  • 3.
    Lecture 4: InformationRepresentation Number Systems Number Systems Decimal Number System Decimal Number System Base is 10 or ‘D’ or ‘Dec’ Ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Each place is weighted by the power of 10 Example: 123410 or 1234D = 1 x 103 + 2 x 102 + 3 x 101 + 4 x 100 = 1000 + 200 + 30 + 4 $1,000 $100 $10 $1
  • 4.
    Lecture 4: InformationRepresentation Binary Number System Binary Number System Base is 2 or ‘b’ or ‘B’ or ‘Bin’ Base is 2 or ‘b’ or ‘B’ or ‘Bin’ Two symbols: 0 and 1 Two symbols: 0 and 1 Each place is weighted by the power of 2 Each place is weighted by the power of 2 Example Example: : 1011 10112 2 or or 1011 1011 B B = 1 x = 1 x 2 23 3 + 0 x + 0 x 2 22 2 + 1 x + 1 x 2 21 1 + 1 x + 1 x 2 20 0 = 8 + 0 + 2 +1 = 8 + 0 + 2 +1 = 11 = 1110 10 11 11 in decimal number system is in decimal number system is 1011 1011 in binary number system in binary number system
  • 5.
    Lecture 4: InformationRepresentation Conversion between Decimal and Binary Conversion between Decimal and Binary Conversion from decimal number system to binary Conversion from decimal number system to binary system system Question: represent 3410 in the binary number system Answer: using the divide-by-2 technique repeatedly If we write the remainder from right to left : 3410  1 x 25 + 0 x 24 + 0 x 23 + 0 x 22 + 1x 21 + 0 x 20  1000102 34 8 17 2 4 1 0 1 0 0 0 1 Remainder div-by-2 div-by-2 div-by-2 div-by-2 div-by-2 div-by-2
  • 6.
    Lecture 4: InformationRepresentation Converting decimal to binary Converting decimal to binary Example: 162: Example: 162: So, 162 So, 16210 10 = = 10100010 101000102 2 162 / 2 = 81 rem 0 81 / 2 = 40 rem 1 40 / 2 = 20 rem 0 20 / 2 = 10 rem 0 10 / 2 = 5 rem 0 5 / 2 = 2 rem 1 2 / 2 = 1 rem 0 1 / 2 = 0 rem 1
  • 7.
    Lecture 4: InformationRepresentation Some Exercises Some Exercises 13D = (?) B 23D = (?) B 72D = (?) B 1101 1101B B
  • 8.
    Lecture 4: InformationRepresentation Conversion from binary number system to Conversion from binary number system to decimal system decimal system Example: check if 1000102 is 3410 using the :weights” appropriately 1000102  1 x 25 + 0 x 24 + 0 x 23 + 0 x 22 + 1 x 21 + 0 x 20  32 + 0 + 0 + 0 + 2 + 0  3410
  • 9.
    Lecture 4: InformationRepresentation Some Exercises Some Exercises Ex: 0101 Ex: 0101B B  ( ? ) ( ? ) D D Ex: 1100 Ex: 1100B B   ( ? ) ( ? ) D D Ex: 0101 1100 Ex: 0101 1100B B   ( ? ) ( ? ) D D Bit 4 23 = 8 Bit 3 22 = 4 Bit 2 21 = 2 Bit 1 20 = 1 0 0 1 1 0 0 1 1 4 1 + = 5D 1 1 0 0 8 4 2 1 = 12D 0 1 0 1 1 1 0 0 128 64 32 16 8 4 2 1 = 92D
  • 10.
    Lecture 4: InformationRepresentation Binary Arithmetic on Integers Binary Arithmetic on Integers Addition Addition a b a + b 0 0 0 1 1 0 1 1 13D + 5D 18D 15D + 10D 25D 0 1 1 0 1 Example: find binary number of a + b • If a = 13D , b = 5D • If a = 15D, b = 10D 1 1 1 1 1 0 1b 0 1 0 1b + 1 1 1 1 1 1 1b 1 0 1 0b 1 1 0 0 1b + 1 0b 0 0 1 Carry bit
  • 11.
    Lecture 4: InformationRepresentation Multiplication Multiplication Binary Arithmetic on Integers Binary Arithmetic on Integers (cont.) (cont.) a b a x b 0 0 0 1 1 0 1 1 1 0 0 0 0 1b x 1 0 1b 0 1 0 0  33D  5D  165D 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 1 0 1b Example: if a = 100001b , b = 101b , find a x b
  • 12.
    Lecture 4: InformationRepresentation Hexadecimal Number System Hexadecimal Number System Hexadecimal Number System Hexadecimal Number System Base = 16 or ‘H’ or ‘Hex’ 16 symbols: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A(=10), B(=11), C(=12), D(=13), E(=14), F(=15)} Hexadecimal to Decimal Hexadecimal to Decimal (an-1an-2…a1a0)16 = (an-1 x 16n-1 + an-2 x 16n-2 + …+ a1 x 161 + a0 x 160 )D Example: (1C7)16 = (1 x 162 + 12 x 161 + 7 x 160 )10 = (256 + 192 + 7)10 = (455)10 Decimal to Hexadecimal Decimal to Hexadecimal Repeated division by 16 Similar in principle to generating binary codes binary codes Example Example: (829) : (829)10 10 = = (? (? ) )16 16 Stop, since quotient = 0 Stop, since quotient = 0 Hence, (829) Hence, (829)10 10 = (3313) = (3313)16 16 Divide-by-16 Quotient Remainder 829 / 16 51 / 16 3 / 16 51 3 0 13 3 3 (33D) (33D)16 16
  • 13.
    Lecture 4: InformationRepresentation Hexadecimal Conversions Hexadecimal Conversions Hexadecimal to Binary Hexadecimal to Binary Expand each hexadecimal digit to 4 binary bits. Example: (E29)16 = (1110 | 0010 | 1001)2 Binary to Hexadecimal Binary to Hexadecimal Combine every 4 bits into one hexadecimal digit Example: (0101 | 1111 | 1010 | 0110)2 = (5FA6)16
  • 14.
    Lecture 4: InformationRepresentation Octal Number System Octal Number System Octal Number System Octal Number System Base = 8 or ‘o’ or ‘Oct’ 8 symbols: { 0, 1, 2, 3, 4, 5, 6, 7} Octal to Decimal Octal to Decimal (an-1an-2…a1a0)8 = (an-1 x 8n-1 + an-2 x 8n-2 + …+ a1 x 81 + a0 x 80 )10 Example: (127)8 = (1 x 82 + 2 x 81 + 7 x 80 )10 = (64 + 16 + 7)10 = (87)10 Decimal to Octal Decimal to Octal Repeated division by 8 (similar in principle to generating binary codes) Example: (213)10 = (? )8 Stop, since quotient = 0 Stop, since quotient = 0 Hence, (213) Hence, (213)10 10 = (325) = (325)8 8 Divide-by -8 Quotient Remainder Octal digit 213 / 8 26 / 8 3 / 8 26 3 0 5 2 3 Lower digit = 5 Second digit =2 Third digit =3
  • 15.
    Lecture 4: InformationRepresentation Octal to Binary Expand each octal digit to 3 binary bits. Example: (725)8 = (111 | 010 | 101)2 Binary to Octal Combine every 3 bits into one octal digit Example: (110 | 010 | 011)2 = (623)8 Visit: tshahab.blogspot.com
  • 16.
    Lecture 4: InformationRepresentation Mini Homework Mini Homework 1) Convert the following binary numbers to decimal numbers: (a) 0011 B (b) 0101 B (c) 0001 0110 B (d) 0101 0011 B 2) Convert the following decimal numbers to binary: (a) 21 D (b) 731 D (c) 1,023 D
  • 17.
    Lecture 4: InformationRepresentation 3) Convert the following binary numbers to hexadecimal numbers: (a) 0011 B (b) 0101 B (c) 0001 0110 B (d) 0101 0011 B (a) 21 D (b) 731 D (c) 1,023 D 4.) Perform the following binary additions and subtractions. Show your work without using decimal numbers during conversion. (a) 111 B + 101 B (b) 1001 B + 11 B

Editor's Notes

  • #1 Visit: tshahab.blogspot.com
  • #17 Visit: tshahab.blogspot.com