CH 04 Number System
CH 04 Number System
Computer Engineering
CEN 123, Fall 2024-2025
Assoc. Prof. Dr. Mümine KAYA KELEŞ
Department of Computer Engineering
Adana Alparslan Türkeş Science and Technology University
CHAPTER 4
NUMBER SYSTEM
COURSE OUTLINE
1. Number System
2. Decimal Number Representation
3. Generic Number Representation
4. Counting numbers with base-b
5. Convert between different bases
6. Negative Number Representation
7. Binary Computation
NUMBER SYSTEM
(A is coefficient; b is base)
Generalize for a given number N w/
base-b
N = An-1 An-2 … A1 A0
N = An-1*bn-1 + An-2*bn-2 + … + A2*b2 + A0*b0
**Note that A < b
GENERIC NUMBER REPRESENTATION
Example:
In 734, value of 7 is 7 hundreds or 700 or 7 × 100 or 7 × 102
In 971, value of 7 is 7 tens or 70 or 7 × 10 or 7 × 101
In 207, value 0f 7 is 7 units or 7 or 7 × 1 or 7 × 100
0 10 20 90 100 0 10 20 70 100
1 11 21 91 101 1 11 21 71 101
2 12 22 92 102 2 12 22 72 102
3 13 23 93 103 3 13 23 73 103
4 14 24 ….. 94 104 4 14 24 ….. 74 104
5 15 25 95 105 5 15 25 75 105
6 16 26 96 106 6 16 26 76 106
7 17 27 97 107 7 17 27 77 107
8 18 28 98 108
9 19 29 99 109
Each binary digit is also called a bit. Binary number system is also
positional value system, where each digit has a value expressed in powers
of 2, as displayed here.
Binary Number System
In any binary number, the rightmost digit is called least
significant bit (LSB) and leftmost digit is called most
significant bit (MSB).
HOW ABOUT BASE-2
0 10 100 1000
1 11 101 1001
110 1010
111 1011
1100
1101
1110
1111
HOW ABOUT BASE-2
0 10 100 1000
1 11 101 1001
110 1010
111 1011
1100
1101
1110
1111
HOW ABOUT BASE-2
Binary = Decimal
DERIVE NUMBERS IN BASE-2
Decimal (base-10) Exercise
(25)10
2 25
Binary (base-2)
2 12 1
(11001)2
2 6 0
2 3 0
1 1
BASE-2
Decimal (base-10) Exercise
(982)10
Binary (base-2)
(1111010110)2
BASE-2
Example
Decimal equivalent of this number is sum of product
of each digit with its positional value.
Octal (base-8)
(1726)8
BASE-8
Example:
(982)10 = (3d6)16
(3d6)16 can be written as (0011 1101 0110)2
We use Base-16 (or Hex) a lot in computer world
Ex: A 32-bit address can be written as 0xfe8a7d20 (0x
is an abbreviation of Hex)
Or in binary form
1111_1110_1000_1010_0111_1101
_0010_0000
EXAMPLE
EXAMPLE
Hexadecimal (base-16)
(3d6)16
CONVERSION IN NUMBER
SYSTEM
Basically we can categorize conversion in three categories:
• Decimal to Any
• Any to Decimal
• Any to Any
DECIMAL TO ANY
Example: Decimal To Binary
DECIMAL TO ANY
6 39
6 6 3
1 0
(0100111)2 = (103)6
NUMBER SYSTEM CONVERSION
BINARY REPRESENTATION OF
NUMBERS
It gets cumbersome saying “binary digit” all the time, so the shorter
term “bit” was invented. A bit is one binary digit. A bit can hold
either a 1 or a 0 (zero).
BINARY REPRESENTATION OF
NUMBERS
A particularly handy size chunk of computer memory happens to be 8
bits long. This size chunk of memory can be used to represent any
number from zero (00000000) to 255 (11111111).
Why does 11111111 (base 2) equal 255 (base 10)? Because it means:
1 x 128 + 1 x 64 + 1 x 32 + 1 x 16 + 1 x 8 + 1 x 4 + 1 x 2 + 1 x 1 = 255
We have a special name for a chunk of memory that is 8 bits long: it is
called a byte. This is the basic unit we use to measure computer
memory size.
BINARY REPRESENTATION OF
NUMBERS
Our computer can understand only (0, 1) language. The binary
numbers are represented in both ways, i.e., signed and unsigned.
The positive numbers are represented in both ways- signed and
unsigned, but the negative numbers can only be described in a
signed way. The difference between unsigned and signed numbers is
that unsigned numbers do not use any sign bit for positive and
negative numbers identification, but the signed number used.
BINARY REPRESENTATION OF
NUMBERS
Positive Signed Binary Numbers
One’s Complement
Two’s Complement (we use this in this
course)
SIGN-MAGNITUDE
Use the most significant bit +0 000
(MSB) to indicate the sign
+1 001
0: positive, 1: negative
+2 010
Problem
Representing zeros? +3 011
Do not work in computation -3 111
We will NOT use it in this -2 110
course !
-1 101
0 100
ONE’S COMPLEMENT
Complement (flip) each bit in a +0 000
binary number
+1 001
Problem
+2 010
Representing zeros?
Do not always work in +3 011
computation -3 100
Ex: 111 + 001 = 000 Incorrect !
-2 101
We will NOT use it in this
course ! -1 110
0 111
TWO’S COMPLEMENT
Complement (flip) each bit in a
binary number and adding 1,
with overflow ignored
Work in computation perfectly
We will use it in this course !
3 011 -3 101
One’s complement One’s complement
100 010
Add 1 Add 1
-3 101 3 011
TWO’S COMPLEMENT
Complement (flip) each bit in a 0 000
binary number and adding 1,
+1 001
with overflow ignored
Work in computation perfectly -1 111
We will use it in this course ! +2 010
-2 110
100
One’s complement
+3 011
011 -3 101
The same 100 represents
Add 1 both 4 and -4
which is no good
?? 100
100
TWO’S COMPLEMENT
Complement (flip) each bit in a 0 000
binary number and adding 1,
+1 001
with overflow ignored
Work in computation perfectly -1 111
We will use it in this course ! +2 010
-2 110
100
One’s complement
+3 011
011 -3 101
MSB = 1 for negative
Add 1 Number, thus 100
represents -4
-4 100
100
010001 (17=16+1)
001011 (11=8+2+1)
---------------
011100 (28=16+8+4)
Unsigned arithmetic
101111 (47)
The carry is 011111 (31)
discarded ---------------
001110 (78?? Due to overflow, note that
62 cannot be represented
by a 6-bit unsigned number)
-7 + 5 = ?
13 – 7
Two’s complement of 07 = 92 + 1 = 93
13 + 93 = 06 (ignore the leftmost carry digit)
817 – 123
Two’s complement of 123 = 876 + 1 = 877
817 + 877 = 694 (ignore the leftmost carry digit)
78291 – 4982
Two’s complement of 04982 = 95017 + 1 = 95018
78291 + 95018 = 73309 (ignore the leftmost carry
digit)
EXAMPLES
Example 1
Suppose we want to add two numbers 69 and 12 together. If we're
to use decimal, we see the sum is 81. But let's use binary instead,
since that's what the computer uses.
EXAMPLES
Example 2
Now suppose we want to subtract 12 from 69. Now, 69 - 12 =
69 + (-12). To get the negative of 12 we take its binary
representation, invert, and add one.
The last is the binary representation for -12. As before, we'll add the two
numbers together.