2 - Digital Representation of Information

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University

Outline
Prelude: Digital Representation
Digital of Information
Representation Positional Number Systems

of Information Decimal Number System


Binary Number System
Octal Number System
VOLKAN KURSUN Hexadecimal Number System
General base-r system
Some material from McGraw Hill

EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN

Stored Program Computers


VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Digital Representation of Information
 Modern computers are built on two key Information is represented in logic circuits as electronic
principles (stored program concept): signals
1) Instructions and data are represented as
Different signal levels represent different digits of
binary numbers
2) These binary numbers are stored in memory information
to be read or written as needed by a program To make the design of logic circuits easier (more
 Stored programs allow a computer to compatible with how transistors operate), each digit is
perform various tasks: allowed to take only two possible values, denoted as 0 and
To switch from one task to another simply load 1
the memory with the corresponding program
These logic levels are implemented as voltage levels in a
and data and tell the computer to begin
executing at a specific location in memory circuit:
 Representing instructions and data with 0 is typically represented with 0V (ground)
binary numbers and letting them share the 1 is typically represented with the power supply voltage
same memory simplifies both the memory (VDD)
hardware and the software: same memory All information in logic circuits is represented as
technology used for both data and instructions
combinations of 0s and 1s (binary digits)
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University

Data Representation in Computers Outline


Prelude: Digital Representation
of Information
Positional Number Systems
Decimal Number System
Binary Number System
Octal Number System
Hexadecimal Number System

EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN


General base-r system
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN

VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University

Number Systems Decimal Numbers (Base 10)


 Human beings typically use decimal (base  Decimal number system has 10 symbols that
10) numbers for counting are called digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9
 Natural choice: we have 10 fingers A number written without any prefix or suffix is
interpreted as decimal. Sometimes a suffix of D may
 Computers use binary (base 2) number
be used to represent decimal numbers explicitly
system Positional number system: every digit, depending on
 Natural choice: transistors have binary its position, has a corresponding weight and value
state: on or off, voltage high or low (an-1an-2an-3…a1a0)10 = an-1*10n-1 + an-2
 In computing, hexadecimal (base 16) and *10n-2 + an-3*10n-3 + …+ a1*101 + a0*100
octal (base 8) number systems are also
commonly used for compact representation  Example: 2019 = 2019D = (2019)10
of binary numbers with many digits (bits)
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
2019 = 2*103 + 0*102 + 1*101 + 9*100
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University

Decimal Numbers with Fractions Outline


Prelude: Digital Representation
of Information
Positional Number Systems
Decimal Number System
Positional number system
Binary Number System
Octal Number System
Hexadecimal Number System

EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN


General base-r system
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN

VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University

Unsigned Number Representation Unsigned Binary Numbers (Base 2)


In computers, unsigned
 Computers use binary (base 2) number system
 Natural choice: transistor on or off, voltage high or low, binary state

 Binary number system has 2 symbols that


number refers to non- are called binary digits (bits): 0 and 1
negative integers A binary number is identified with either a prefix of 0b or 0B
or a prefix of b’bits inside apostrophe’ or a suffix of B or b

(an-1an-2an-3…a1a0)2 = an-1*2n-1 + an-2 *2n-2


Such as 0, 1, 2, 3 … + an-3*2n-3 + …+ a1*21 + a0*20
Example: binary number Example: 0b101011 = b’101011’ =
0b 101 = 5 (base 10) 101011B = (101011)2 = 1*25 + 0*24
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
+ 1*23 + 0*22 + 1*21 + 1*20 = 43
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Unsigned Binary ↔ Decimal Conversion Unsigned Binary ↔ Decimal Conversion
Decimal  Binary
Unsigned Binary  Decimal Decimal  Binary Unsigned Binary  Decimal 11011 = 0b?
0b1001010 = ?ten Decimal Binary
74 = 0b? 0b11011 = ?ten 11011
Binary Decimal Decimal Binary Digit
Binary Decimal Value /2 = 5505 1

Digit Value 74 Digit


/2 = 2752 1
/2 = 1376 0
0 0 x 20 = 0 74/2 = 37 0 1 1 x 20 = 1 /2 = 688 0
1 1 x 21 = 2 37/2 = 18 1 1 1 x 21 = 2 /2 = 344 0
/2 = 172 0
0 0 x 22 = 0 18/2 = 9 0 0 0 x 22 = 0 /2 = 86 0
1 1 x 23 = 8 9/2 = 4 1 1 1 x 23 = 8 /2 = 43 0
/2 = 21 1
0 0 x 24 = 0 4/2 = 2 0 1 1 x 24 = 16 /2 = 10 1
0 0 x 25 = 0 2/2 = 1 0 Σ = 27 /2 = 5 0
1/2 = 0 1 /2 = 2 1
1 1 x 26 = 64 • Same symbols can mean different
/2 = 1 0
Collect  things
Σ = 74ten remainder bits
0b1001010
• Be explicit unless you mean decimal /2 = 0 1
EEE 102 Introduction to Digital Circuit Design in reverse order VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design Collect  0b10101100000011
VOLKAN KURSUN

VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University


Unsigned Binary Integers Unsigned Binary Integers
Decimal equivalent of an n-bit unsigned binary number: Decimal equivalent of an n-bit unsigned binary number:

x = x n−1 2n−1 + x n−2 2n−2 +  + x1 21 + x 0 20 x = x n−1 2n−1 + x n−2 2n−2 +  + x1 21 + x 0 20


Range: 0 to +2n – 1 Range: 0 to +2n – 1
32-Bit Binary Number Example:

0b 0000 0000 0000 0000 0000 0000 0000 1011


Range with 32 bits: 0 to +232 – 1
= 0 + … + 1×23 + 0×22 +1×21 +1×20 0 to +4,294,967,295
= 0 + … + 8 + 0 + 2 + 1 = (11)10

Range with 32 bits: 0 to +232 – 1 Range with 64 bits: 0 to +264 – 1


0 to +18,446,744,073,709,551,615
0 to +4,294,967,295
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
18 quintillion 446 quadrillion 744 trillion 73 billion 709 million 551 thousand 615
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Binary with Fraction to Decimal Decimal Fraction to Base-2 Conversion
Successively multiply the fractions with 2 and record and
collect the integer parts until the fraction becomes zero

Decimal equivalent of an unsigned binary number with fraction:

EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN

VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University


Decimal Fraction to Base-2 Conversion Decimal Fraction to Base-2 Conversion
There is no guarantee that the fraction would become  Successively multiply the fraction by 2 until either
zero after a certain number of steps: repeating binary the fraction becomes 0 or the binary sequence
sequences may be encountered in the fraction starts to repeat
 Successively multiply the fraction by 2 until either  Example: Convert 3.47 to binary
the fraction becomes 0 or the binary sequence 0.47 x2 0.94 0.32 x2 0.64 0.92 x2 1.84
starts to repeat 0.94 x2 1.88 0.64 x2 1.28 0.84 x2 1.68

 Example: Convert 3.47 to binary 0.88 x2 1.76 0.28 x2 0.56 0.68 x2 1.36
Repeating
0.47 x2 0.94 0.32 x2 0.64 0.92 x2 1.84 0.76 x2 1.52 0.56 x2 1.12 0.36 x2 0.72
0.94 x2 1.88 0.64 x2 1.28 0.84 x2 1.68 0.52 x2 1.04 0.12 x2 0.24 0.72 x2 1.44
20-digit
0.88 x2 1.76 0.28 x2 0.56 0.68 x2 1.36 0.04 x2 0.08 0.24 x2 0.48 0.44 x2 0.88 binary
0.76 x2 1.52 0.56 x2 1.12 0.36 x2 0.72 Repeating 0.08 x2 0.16 0.48 x2 0.96 0.88 x2 1.76 sequence
0.52 x2 1.04 0.12 x2 0.24 0.72 x2 1.44 20-digit 0.16 x2 0.32 0.96 x2 1.92 0.76 x2 1.52
0.04 x2 0.08 0.24 x2 0.48 0.44 x2 0.88
binary  3.47 = 0b11.0111100001010001111010…
0.08 x2 0.16 0.48 x2 0.96 0.88 x2 1.76
0.16 x2 0.32 0.96 x2 1.92 0.76 x2 1.52 sequence Repeating 20-digit binary sequence
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Outline Octal Numbers
Prelude: Digital Representation
Use 0o or 0O prefixes or Q or q suffixes to distinguish octal numbers
of Information
Positional Number Systems
Decimal Number System
Binary Number System
Octal Number System
Hexadecimal Number System
General base-r system
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN

VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University


Binary to Octal Conversion Octal to Binary Conversion
Binary equivalent of an octal number with
fraction:

Octal equivalent of an unsigned binary number


with fraction:

EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University

Octal with Fraction to Decimal Outline


Prelude: Digital Representation
Decimal equivalent of an octal of Information
number with fraction:
Positional Number Systems
Decimal Number System
Binary Number System
Octal Number System
Hexadecimal Number System

EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN


General base-r system
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN

VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University


Hexadecimal Numbers (Base 16) Hexadecimal Numbers (Base 16)
 Hexadecimal number system has 16 symbols  Compact representation of bit strings
called hexadecimal digits: 0, 1, 2, 3, 4, 5, 6, 7, 8,
9, A, B, C, D, E, F  4 bits per hexadecimal digit
 Hexadecimal numbers are identified with either 0 0000 4 0100 8 1000 c 1100
a prefix of 0x or 0X or a suffix of H or h
 Compact representation of bit strings
1 0001 5 0101 9 1001 d 1101
 4 bits per hexadecimal digit Nibble: group of 4 bits 2 0010 6 0110 a 1010 e 1110
0 0000 4 0100 8 1000 c 1100 3 0011 7 0111 b 1011 f 1111
1 0001 5 0101 9 1001 d 1101 Example: 0xeca86420 = eca86420H =
2 0010 6 0110 a 1010 e 1110 (eca86420)16 in binary Replace each hexadecimal digit with 4
equivalent bits:

0b1110 1100 1010 1000 0110 0100 0010 0000


3 0011 7 0111 b 1011 f 1111
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University

Binary to Hexadecimal Conversion Hexadecimal ↔ Decimal Conversion


Hexadecimal  Decimal Decimal  Hexadecimal

0x11011 = ?ten 11011 = 0x?


Decimal Hexadecimal
Hexadecimal Decimal Value
Digit 11011
1 1 x 160 = 1 /16 = 688 3
/16 = 43 0
1 1 x 161 = 16
Hexadecimal equivalent of an unsigned 0 0 x 162 = 0
/16 = 2 B
/16 = 0 2
binary number with fraction: 1 1 x 163 = 4096 Collect  0x2B03
1 1 x 164 = 65536 remainders
in reverse
Σ = 69649
order
• Same symbols can mean different things
• Be explicit unless you mean decimal
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN

Conversion Between Radix


VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Outline
Nibble: group of 4 bits
Prelude: Digital Representation
of Information
Positional Number Systems
Decimal Number System
Byte, halfword (2 bytes), word (4 bytes), and
doubleword (8 bytes): data sizes used in Binary Number System
computers (largest data size depends on the width
of the processor datapath and registers). Data are Octal Number System
processed in chunks called bytes, halfwords,
words, and doublewords in a computer Hexadecimal Number System
32-bit words in 32-bit ISA (Example: RV32, ARM-32)
64-bit doublewords in 64-bit ISA (Example: RV64, ARM-64)
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
General base-r system
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
General Base-r System
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University

Decimal to Base-r Conversion

Base-r point
Note: even in numbers with
fractions, the least
significant digit is the
rightmost digit
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN

Base-r to Base-k Conversion


VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University

Decimal to Base-2 Conversion Example-2

to binary

EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN

You might also like