0% found this document useful (0 votes)
5 views

CH 04 Number System

This document serves as an introduction to number systems in computer engineering, covering various bases including decimal, binary, octal, and hexadecimal. It explains how numbers are represented in these systems, the concept of positional value, and the methods for converting between different bases. Additionally, it discusses the representation of negative numbers and the use of ASCII for character encoding.

Uploaded by

mdursun5040
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

CH 04 Number System

This document serves as an introduction to number systems in computer engineering, covering various bases including decimal, binary, octal, and hexadecimal. It explains how numbers are represented in these systems, the concept of positional value, and the methods for converting between different bases. Additionally, it discusses the representation of negative numbers and the use of ASCII for character encoding.

Uploaded by

mdursun5040
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Introduction to

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 set of values used to represent different quantities is known as


Number System".

The digital computer represents all kinds of data and information in


binary numbers. It includes audio, graphics, video, text and
numbers. The total number of digits used in a number system is
called its base or radix.
NUMBER SYSTEM
DECIMAL NUMBER REPRESENTATION
 Decimal number system is a base 10 number system
having 10 digits from 0 to 9. This means that any numerical
quantity can be represented using these 10 digits. Decimal
number system is also a positional value system. This
means that the value of digits will depend on its position.
 Example: 90134 (base-10, used by Homo Sapien)
= 90000 + 0 + 100 + 30 + 4
= 9*104 + 0*103 + 1*102 + 3*101 + 4*100
 How did we get it?
10 90134
10 9013 4
10 901 3
10 90 1
9 0
GENERIC NUMBER REPRESENTATION
 90134
= 9*104 + 0*103 + 1*102 + 3*101 + 4*100
 A4 A3 A2 A1 A0 for base-10 (or radix-10)
= A4*104 + A3*103 + A2*102 + A1*101 + A0*100

(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

 The weightage of each position can be represented as


follows:
COUNTING NUMBERS WITH BASE-B

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

Base-10 How about Base-8


Binary Number System
 The easiest way to vary instructions through electric signals is two-state
system – on and off. On is represented as 1 and off as 0, though 0 is not
actually no signal but signal at a lower voltage. The number system having
just these two digits – 0 and 1 – is called binary number system.

 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

0=0 10 = 2 100 = 4 1000 = 8


1=1 11 = 3 101 = 5 1001 = 9
110 = 6 1010 = 10
111 = 7 1011 = 11
1100 = 12
1101 = 13
1110 = 14
1111 = 15

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.

110102 = 1×24 + 1×23 + 0×22 + 1×21 + 0×20


= 16 + 8 + 0 + 2 + 0
= 2610
Octal Number System

 Octal number system has eight digits – 0, 1, 2, 3, 4, 5, 6


and 7. Octal number system is also a positional value
system with where each digit has its value expressed in
powers of 8, as shown here:
BASE-8
 Decimal (base-10)  Exercise
 (982)10

 Octal (base-8)
 (1726)8
BASE-8
 Example:

 Decimal equivalent of any octal number is sum of


product of each digit with its positional value.

7268 = 7×82 + 2×81 + 6×80


= 448 + 16 + 6
= 47010
BASE-8
 Example:

 Decimal equivalent of any octal number is sum of


product of each digit with its positional value.

7268 = 7×82 + 2×81 + 6×80


= 448 + 16 + 6
= 47010
BASE-16
 Decimal (base-10) 0
 0
 (982)10 1
 1
 Hexadecimal (base-16)  2 2
 Hey, what do we do when we  3 3
count to 10?? 4
 4
 5 5
 6 6
 7 7
 8 8
 9 9
 10 a
 11 b
 12 c
 13 d
 14 e
 15 f
BASE-16

 Let’s convert the hexadecimal number #E3B to


decimal.
BASE-16

 (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

 Decimal equivalent of any hexadecimal number is


sum of product of each digit with its positional
value.

27FB16 = 2×163 + 7×162 + 15×161 + 10×160


= 8192 + 1792 + 240 +10
= 1023410
Number System Relationship
 The following table depicts the relationship between decimal,
binary, octal and hexadecimal number systems.
NUMBER EXAMPLES WITH
DIFFERENT BASES
 Decimal (base-10)  Others examples:
 (982)10  base-9 = (1321)9
 Binary (base-2)  base-11 = (813)11
 (01111010110)2  base-17 = (36d)17
 Octal (base-8)
 (1726)8

 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

Example: Decimal To Octal Example: Decimal To Hexadecimal


ANY TO DECIMAL
Example: Binary To Decimal

Symbol X Base of Source Sequence of Symbol


ANY TO DECIMAL
Example: Octal To Decimal Example: Hexadecimal To Decimal
ANY TO ANY

Example: Binary To Hexadecimal

To convert from binary to hexadecimal using indirect conversion.


First convert from Binary to Decimal then Decimal to
Hexadecimal.
CONVERT BETWEEN DIFFERENT
BASES
 Convert a number base-x to base-y, e.g. (0100111)2 to (?)6
 First, convert from base-x to base-10 if x  10
 Then convert from base-10 to base-y

0100111 = 026 + 125 + 024 + 023 + 122 + 121 + 120 = 39

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

 Negative Signed Binary Numbers


BINARY REPRESENTATION OF
NUMBERS
BINARY REPRESENTATION OF
NUMBERS
ASCII REPRESENTATION OF
CHARACTERS
 ASCII Code (American Standard Code for Information Interchange) is
used for equating letters to numbers.
 The capital letter A is represented by the number 65 in the ASCII code (65 is
01000001 in binary).
NEGATIVE NUMBER
REPRESENTATION
 Options
 Sign-magnitude

 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

MSB is Most Significant Bit.


TWO’S COMPLEMENT
 Example:
0 000
 Find -1 using two's complement numbers
 1 = 001 +1 001
Adding 0 to the front becomes 0001

-1 111
 'Inverted' becomes 1110
 Add 1 = 1111 (-8 + 4 + 2 + 1 = -1) +2 010
-2 110
 Find -4 using two's complement numbers
 4 = 100 +3 011
 Adding 0 to the front becomes 0100
 'Inverted' becomes 1011
-3 101
 Add 1 = 1100 (-8 + 4 = -4)
-4 100
TWO’S COMPLEMENT
 TABLE REPRESENTING 1’S & 2’S COMPLEMENTS OF DECIMAL
NUMBERS
TWO’S COMPLEMENT SUMS
 Using two's complement, the CPU can perform arithmetic using
binary addition. For example:
 -7 + 7 in two's complement binary would be calculated as:

 In two's complement, if the final result overflows the remaining carry


number is simply discarded. For example:
 -3 + 4 in two's complement binary would be calculated as:
BINARY COMPUTATION

010001 (17=16+1)
001011 (11=8+2+1)
---------------
011100 (28=16+8+4)

Unsigned arithmetic Signed arithmetic (w/ 2’s complement)


010001 (17=16+1) 010001 (17=16+1)
101011 (43=32+8+2+1) 101011 (-21: 2’s complement=010101=21)
--------------- ---------------
111100 (60=32+16+8+4) 111100 (2’s complement=000100=4, i.e. -4)
BINARY COMPUTATION

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)

Signed arithmetic (w/ 2’s complement)


101111 (-17 since 2’s complement=010001)
The carry is 011111 (31)
discarded ---------------
001110 (14)
BINARY COMPUTATION

-7 + 5 = ?

-7 is 1001 and 5 is 0101. 1001 is added to 0101 to give 1110.


1110 is -2 if converted back to denary in two's complement.
APPLICATION OF TWO’S
COMPLEMENT

 The first Pocket Calculator “Curta”


used Two’s complement method for
subtraction
 First complement the subtrahend
 Fill the left digits to be the same length
of the minuend
 Complemented number = (9 – digit)
 4’s complement = 5
 7’s complement = 2
 0’s complement = 9
 Add 1 to the complemented number
 Perform an addition with the minuend
EXAMPLES

 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.

We result in 57, which is 69-12.


EXAMPLES
Example 3
Lastly, we'll subtract 69 from 12. Similar to our operation in example
2, 12 - 69 = 12 + (- 69). The two's complement representation of 69
is the following. I assume you've had enough illustrations of
inverting and adding one.

So we add this number to 12.

This results in 12 - 69 = -57, which is correct.


Kilobytes, Megabytes,
Gigabytes
 Memory capacity and data storage capacity for computers are
measured in bytes. File sizes are also measure in bytes.

 A kilobyte (KB) is approximately 1,000 bytes. But it is NOT


exactly 1000 bytes; it is 1024 bytes. Because 1024 is exactly
10000000000 in binary; a nice multiple of two is very handy
for the computer.

 1KB = 1024 Byte (2^10 Byte)


 1 MB = 1024 KB = 1048576 Byte (2^20 Byte)
 1 GB = 1024 MB = 1048576 KB = 1073741824 Byte (2^30 Byte)
 1 TB = 1024 GB
 1 PB = 1024 TB
 …
Kilobytes, Megabytes,
Gigabytes

You might also like