Number_System
Number_System
Storage Representation
𝑛
H=- 𝑖=1 𝑝𝑖 ∗ 𝑙𝑜𝑔2(𝑝𝑖)
Bit and Byte
A bit is the smallest unit of data stored in a computer and it has a value of 0 or 1
In computers, bits are stored electronically in RAM and auxiliary storage devices
The storage device itself doesn’t know what the bit pattern represents, but
That is, data is coded then stored and when retrieved it is decoded
A byte is a string of 8 bits and is called a character when the data is text
Bits, Bytes, and Words
A bit is a single binary digit (a 1 or 0).
A byte is 8 bits
5
The Decimal Number System
• The decimal number system is a positional number system.
• Example:
Value 5 6 2 1 1 X 100 = 1
Position 4 3 2 1 2 X 101 = 20
Address 103 102 101 100 6 X 102 = 600
5 X 103 = 5000
6
The Decimal Number System (con’t)
• The decimal number system is also known as base 10. The values of the
positions are calculated by taking 10 to some power.
7
The Binary Number System
• The binary number system is also known as base 2. The values of
the positions are calculated by taking 2 to some power.
8
The Binary Number System (con’t)
• The binary number system is also a positional numbering system.
• Instead of using ten digits, 0 - 9, the binary system uses only two digits,
0 and 1.
1 0 0 1 1 0 1
26 25 24 23 22 21 20
9
Converting from Binary to Decimal
1 0 0 1 1 0 1 1 X 20 = 1
26 25 24 23 22 21 20 0 X 21 = 0
1 X 22 = 4
20 = 1 24 = 16 1 X 23 = 8
21 = 2 25 = 32 0 X 24 = 0
22 = 4 26 = 64 0 X 25 = 0
23 = 8 1 X 26 = 64
7710
10
Converting from Binary to Decimal (con’t)
Practice conversions:
Binary Decimal
11101
1010101
100111
11
Converting From Decimal to Binary (con’t)
• Make a list of the binary place values up to the number being converted.
• Example: 4210
25 24 23 22 21 20
32 16 8 4 2 1
1 0 1 0 1 0
12
Converting From Decimal to Binary (con’t)
Practice conversions:
Decimal Binary
59
82
175
13
Working with Large Numbers
• 0101000010100111 = ?
• Humans can’t work well with binary numbers; there are too many digits to
deal with.
14
The Hexadecimal Number System
• The hexadecimal number system is also known as base 16. The
values of the positions are calculated by taking 16 to some power.
15
The Hexadecimal Number System (con’t)
Binary Decimal Hexadecimal Binary Decimal Hexadecimal
0 0 0 1010 10 A
1 1 1 1011 11 B
10 2 2 1100 12 C
11 3 3 1101 13 D
100 4 4 1110 14 E
101 5 5 1111 15 F
110 6 6
111 7 7
1000 8 8
1001 9 9
16
The Hexadecimal Number System (con’t)
Example of a hexadecimal number and the values of the positions:
3 C 8 B 0 5 1
166 165 164 163 162 161 160
17
Example of Equivalent Numbers
Binary: 1 0 1 0 0 0 0 1 0 1 0 0 1 1 12
Decimal: 2064710
Hexadecimal: 50A716
Notice how the number of digits gets smaller as the base increases.
18
Binary Representation
Why binary representation (as suppose to decimal or octal,
etc..)?
◦ Because the devices that store and manage the digital data are far
less expensive and complex for binary representation.
◦ They are also far more reliable when they have to represent one out
of two possible values.
To represent more than two things, we need multiple bits. Two bits can
represent four things because there are four combinations of 0 and 1 that
can be made from two bits: 00, 01, 10,11.
Roman Numbers
HexaDecimal
◦ Ranges from 0 to F
Primitive Data Structure
Basic representation of any data.
Integer
Real Numbers
Character
Basic Operations on Primitive DS
CREATE
◦ Declare n, a, b as integer
DESTROY
SELECTION
UPDATE
Na+b
Integer
Represent the quantity and discrete in nature
Signed numbers
Unsigned Integer
An unsigned integer is an integer without a sign, that is, a non-negative integer
They range from zero to infinity, but no computer can store all the integers in that
range
Let’s use 8 and 16-bit (1 and 2 bytes) storage locations in our examples
The length of storage is set by the data type the programmer specifies for a
variable
Unsigned Integer
An unsigned integer is stored as its value when represented as a binary
number
Find the largest power of 2 that doesn’t exceed the number and place a 1 in
that cell:
Subtract that power of 2 from the number and use this as the new number:
13 – 8 = 5
Unsigned Integer
Then continue in this way until the sum of the powers of two equals the
number:
Note that 8 + 4 + 1 = 13
Unsigned Integer
Then fill in the remaining cells with zeros:
In this case, depending on the system, one may or may not receive an error
message
So, one must not store a number that is larger than the maximum for a
given length of storage
(and zero)
The leading bit is designated as the sign bit: 0 for positive or zero, 1 for negative
So, in 1-byte of storage the maximum number storable is not 255 as it was for
Range: 0 to +2n – 1
Example
0000 0000 0000 0000 0000 0000 0000 10112
= 0 + … + 1×23 + 0×22 +1×21 +1×20
= 0 + … + 8 + 0 + 2 + 1 = 1110
Using 32 bits
0 to +4,294,967,295
Signed Positive Integer
To determine what the sign-and-magnitude representation of a positive
decimal number is:
Because 16 + 1 = 17
Concerns
Not economical
Modulo M = RN
◦ -x = M – x
2’s complement
Integer 2’s Complement Integer 2’s Complement
0 0000 -1 (16-1=15) 1111
1 0001 -2 (16-2=14) 1110
2 0010 -3 (16-3=13) 1101
3 0011 -4 (16-4=12) 1100
4 0100 -5 (16-5=11) 1011
5 0101 -6 (16-6=10) 1010
6 0110 -7 (16-7=9) 1001
7 0111 -8 (16-8=8) 1000
Example
Using 32 bits
–2,147,483,648 to +2,147,483,647
2s-Complement Signed Integers
Bit 31 is sign bit
◦ 1 for negative numbers
◦ 0 for non-negative numbers
–(–2n – 1) can’t be represented
Non-negative numbers have the same unsigned and 2s-complement representation
Some specific numbers
◦ 0: 0000 0000 … 0000
◦ –1: 1111 1111 … 1111
◦ Most-negative: 1000 0000 … 0000
◦ Most-positive: 0111 1111 … 1111
Signed Negation
Complement and add 1
◦ Complement means 1 → 0, 0 → 1
x x 1111...1112 1
x 1 x
Example: negate +2
Subtraction : 5 - 3 = 5 + (-3)
Diminished radix-complement
Also called as “1’s complement”.
DRCOMP(X) = Rn – 1 – X
Rn =Modulo representation
7+7 = -1, -7 – 7 = 0
BCD needs more number of bits than binary to represent the decimal
number. So BCD is less efficient than binary.
Real numbers
Fixed Point Representation
General Format
To convert this example find the sum value of the entire pattern as though a
standard binary number:
To convert this example find the sum value of the entire pattern as though a standard
binary number:
Then subtract the current excess value, 16, from the sum, (30 - 16). The result is a
signed value, + 14.
Therefore, it is evident that in excess notation, the sign bit of 0 represents the
negative sign and 1 represents the non-negative sign to denote a signed value.
Real Number - Fractional part or mantissa
F must lie in the interval R-1 <= F < 1
Data Interpretation in computer
Character String
represent the character "A" and 11000001 for character "B" and
The final ASCII code in the 7-bit chart is the control character DEL with
decimal code 127
Extended ASCII & Unicode
The eight-bit ASCII chart is sometimes called Extended ASCII
The seven-bit ASCII codes are the same in eight-bit chart except have
a zero at the left
Some manufactures use the extra bit to create additional special
characters, these however are nonstandard, e.g., using decimal 171
for ½, or 246 for ÷
Unicode is another scheme developed so that the many symbols in
international languages may be represented. It also uses bit patterns.
UTF-32 uses 32 bits.
EBCDIC
The extended binary coded decimal interchange code (EBCDIC) is an
8-bit alphanumeric code which has been extensively used by IBM in
its mainframe applications.