Unit1 2
Unit1 2
Unit1 2
Representation of Information
in Computers
Contents
2.1. Number Systems
2.2. Number Representation in Computers - Units of
Information
2.3. Representation of Integers
2.4. Operations on Integers
2.5. Logical operations on Binary Numbers
2.6. Symbol Representation
2
2.1. Number Systems
• Decimal System
• Base-b System
• Convertion from Decimal to Base-b
• Binary System
• Hexadecimal System
• Octal System
3
Number Categories
• Natural numbers
• Integers
• Rational numbers
• Irrational numbers
4
Decimal System
5
Decimal System (cont’d)
n 1
j
j
d * 10
where n is thej 0total number of digits, and dj is
the j th digit from the rightmost position in the
decimal number.
6
Base-b System
where n is the total number of digits, and dj is the j th digit from the
rightmost position in the decimal number.
• When the base is higher than 10, we need symbols to represent the
digits that correspondent to the decimal values of 10 and beyond.
7
Example
Convert 11101.112 to Decimal
8
Convert integers from decimal to base b
Remainder Method:
• Let value = (dn-1 dn-2 … d2 d1 d0)10.
• First divide value by b, the remainder is the least
significant digit b0.
• Divide the result by b, the remainder is b1.
• Continue this process until the result is less than b, giving
the most significant digit, bm-1.
• The result is bm-1 bm-2 … b2 b1 b0
9
Example 1
Use Remainder Method to convert 12 (base 10) to base 2
10
Convert Decimal Fractions to Base-b
• Begin with the decimal fraction and multiply by b. The
whole number part of the result is the first digit to the
right of the point.
11
Example 1
Convert the decimal value .625 to a binary representation
• 0.625 x 2 = 1.25
The first binary digit to the right of the point is a 1.
• 0.25 x 2 = 0.50,
The second binary digit to the right of the point is a 0.
• 0.50 x 2 = 1.00
The third binary digit to the right of the point is a 1.
• We had 0 as the fractional part of our result,
12
Example 2
Binary representation of the decimal fraction 0.1
1. .1 x 2 = 0.2
The first binary digit to the right of the point is a 0
2. .2 x 2 = 0.4
The second binary digit to the right of the point is also a 0.
3. .4 x 2 = 0.8
The third binary digit to the right of the point is also a 0.
4. .8 x 2 = 1.6
The fourth binary digit to the right of the point is a 1.
5. .6 x 2 = 1.2
The fifth binary digit to the right of the point is a 1.
6. The next step to be performed (multiply 2. x 2) is exactly the same action
we had in step 2. We are then bound to repeat steps 2-5, then return to
Step 2 again indefinitely
.1 (decimal) = .00011001100110011 . . .
The repeating pattern is 0011
13
Binary System
• All data, including programs, in a computer system is
represented in terms of groups of binary digits
• A single bit can represent one of two values, 0 or 1.
• If we have several symbols to represent, we can make a
one-to-one correspondence between the patterns and the
symbols.
• Example : 0, 1, 2, 3 are mapped to the patterns 00,
01, 10, 11
• A group of k binary digits (bits) can be used to represent 2k
symbols
14
Hexadecimal System
15
Octal System
• The octals numbers include only the representations for
the values from 0 to 7: 0, 1, 2, 3, 4, 5, 6, 7
• Example:
235 . 648
= 2x82 + 3x81 + 5x80 + 6x8-1 + 4x8-2
= 157. 812510
16
Data Representation in a Computer
Units of Information
•Basic Principles
•Units of Information
17
Basic Principles
• Data can be numbers, symbols, images, sounds . . .
• To store in computers, it’s necessary to represent
data in term of bit patterns
• There are different ways to encode different types of
data
• Numbers are convert to their binary
representations following some standard.
• Symbols are assigned a bit pattern
• Other data must be digitalized.
18
Data and Computers
• Every task, a computer manages data in some way
• In the past, computers dealt exclusively with numeric and
textual data
• At present, computers are multimedia devices -> deal with
different type of data:
• Numbers
• Text
• Audio
• Images and Graphics
• Video
• All of data is stored as binary digits: strings of 1s and 0s
19
2.2. Number Representation in
Computers - Units of Information
20
Analog and Digital Information
21
Binary Representation
22
Representing Audio Information
• Digitize the sound wave
• Sampling: periodically measure the voltage of the
signal and record appropriate value
• Reproduce the sound: Use stored voltage values to
create a new continuous electronic signal
• Audio format : WAV,AU, AIFF, VQF, MP3
23
Representing Colors
• Often expressed as an RGB (red – green – blue)
value
• Three numbers indicate the contribution of each of
three primary colors
• Amount of data that used to represent a color is
called color depth
• HiColor: 16 bit color depth
• TrueColor: 24bit color depth
24
Three Dimensional Color Space
25
Some TrueColor RGB Values
26
Digitized Images and Graphics
• Image is a collection of individual dots called pixel
• Each pixel is composed of a single color
• The number of pixel used to represent a picture is
called resolution
27
Categorization of Data Types
• Basic types : the standard scalar predefined types that one
would expect to find ready for immediate use in any
imperative programming language
• Structured types: made up from such basic types or other
existing higher level types.
28
Units of information
• The smallest unit of information a computer can use
is bit (Binary Digit)
• The difference between two states (high current and
low current) is represented as one of two numbers (1
or 0).
• A collection of 8 bits are put together to form a byte
• Binary prefixes can be used to quantify computer
memory sizes
• Each successive prefix is multiplied by 1024 (210)
rather than the 1000 (103)
29
Units of information
30
Representation of Integers
• Unsigned Integers
• Signed Integers
31
Unsigned Integers
32
Signed Integers
• The most significant bit is set to 0 and 1 for positive and
negative numbers
• Example
+4210 = 001010102
and so
-4210 = 110101102
• All number whose leftmost bit is 1 is considered negative
33
Signed Integers (cont’d)
• If we have 4 bits in our representation then,
• The most positive representable number using sign-and-
magnitude is 0111
• The most negative representable number using sign-and-
magnitude is 1000
• How to represent negative number?
34
Two’s Complement
• Representation for signed binary numbers
• Leading bit is a sign bit
• Binary number with leading 0 is positive
• Binary number with leading 1 is negative
• Magnitude of positive numbers is just the binary representation
• Magnitude of negative numbers is found by
• Complement the bits: replace all the 1's with 0's, and all the 0's with 1's
• Add one to the complemented number
• The carry in the most significant bit position is thrown away when
performing arithmetic
35
Example
Performing two's complement on the decimal 42 to get -42
• Using a eight-bit representation
36
Two's Complement Arithmetic
• Computing 50 - 42 using a two's complement
representation with eight-bit numbers
50 - 42 = 50 + (-42) = 8
00110010 50
38
Addition and Subtraction
• Addition
• Subtraction
39
Binary Addition
0+0=0
0+1=1
1+0=1
1 + 1 = 0, and carry 1 to the next more significant bit
40
Example
00011010 + 00001100 = 00100110
1 1 carries
0 0 0 1 1 0 1 0 = 26 (base 10)
+ 0 0 0 0 1 1 0 0 = 12 (base 10)
0 0 1 0 0 1 1 0 = 38 (base 10)
41
Binary Subtraction
0-0=0
0 - 1 = 1, and borrow 1 from the next more significant bit
1-0=1
1-1=0
42
Multiplication and Division
• Multiplication
• Division
43
Binary Multiplication
0x0=0
0x1=0
1x0=0
1 x 1 = 1, and no carry or borrow bits
44
Example
00101001 × 00000110 = 11110110
0 0 1 0 1 0 0 1 = 41(base 10)
× 0 0 0 0 0 1 1 0 = 6 (base 10)
0 0 0 0 0 0 0 0
0 0 1 0 1 0 0 1
0 0 1 0 1 0 0 1
0 0 1 1 1 1 0 1 1 0 = 246 (base 10)
45
Binary Division
46
Logical Operations on Binary Numbers
47
Logical Operations with One or Two Bits
AND: Compares 2 bits and if they are both 1, then the result
is 1, otherwise, the result is 0.
OR: Compares 2 bits and if either or both bits are 1, then the
result is 1, otherwise, the result is 0.
XOR: (Exclusive OR) : Compares 2 bits and if exactly one
of them is 1 then the result is 1 otherwise (if the bits are
the same), the result is 0.
NOT: Changes the value of a single bit. If it is a 1, the result
is 0; if it is a 0, the result is 1.
Truth Table of Logical Operations
48
Logical Operations
with One or Two Integers
• NOT
• AND
• OR
• XOR
49
NOT operation
Unary operation which performs logical negation on
each bit, forming the ones' complement of the given
binary value. Digits which were 0 become 1, and vice
versa.
Example:
NOT 0111
= 1000
50
AND operation
• An AND operation takes two binary representations of
equal length and performs the logical AND operation on
each pair of corresponding bits. In each pair, perform
AND operation on two bits
• Example:
0101
AND 0011
= 0001
51
OR operation
• An OR operation takes two bit patterns of equal
length, and produces another one of the same length
by matching up corresponding bits (the first of each;
the second of each; and so on) and performing the
logical OR operation on each pair of corresponding
bits.
• For example:
0101
OR 0011
= 0111
52
XOR Operation
• An exclusive or operation takes two bit
patterns of equal length and performs the
logical XOR operation on each pair of
corresponding bits.
• For example:
0101
XOR 0011
= 0110
53
Symbol Representation
Basic Principles
ASCII Code Table
Unicode Code Table
54
Basic Principles
• Text documents can be decomposed into individual
characters
• It's important to handle character data
• Character data isn't just alphabetic characters, but also
numeric characters, punctuation, spaces, etc
• They need to be represented in binary
• There aren't mathematical properties for character data, so
assigning binary codes for characters is somewhat arbitrary
55
Character Set
• A list of characters and the codes used to represent
each one.
• By using a particular character set, computer
manufacturers have made the processing of data
easier.
• Two popular character sets: ASCII & Unicode
56
ASCII Code Table
• ASCII -- American Standard Code for Information Interchange
- permitted machines from different manufacturers to exchange
data.
• The ASCII standard was developed in 1963
57
The Standard ASCII Code Table
58
The extended ASCII characters
59
Limitations of ASCII character set
• String data types allocated one byte per character
• The extended version of ASCII which have 256
characters is ehough for English but not enough for
international use
• Logographic languages such as Chinese, Japanese,
and Korean need far more than 256 characters for
reasonable representation.
• Vietnamese need 61 characters for representation.
• Where can we find number for our characters?
60
Unicode Code Table
61
Unicode Character Set
62
Some Symbols in the Unicode Character Set
63
Advantages of using Unicode
64