Data Representation

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 29

Digital Design

Week 2
Data, Representation &
Numeracy
Data, Representation & Numeracy
– what is data
Data refers to raw information that consists of basic facts and figures.
Computer data include different forms of data, such as numerical data,
images, coding, notes, and financial data.
– how is data represented in computers
Computers use 1s and 0s because data is stored as binary
numbers.
– how is data manipulated and processed
Data processing refers to the manipulation, analysis, and transformation
of raw data into meaningful information or knowledge.
Data manipulation is the process of extracting information and applying
logic to it to generate a completely different set of data. In other words,
data is modified when manipulated and stored in the same location.
Bits, Bytes, Words ...
• The basic units of data are organized as follows
– bit
• this is the fundamental unit of data
• 2-state switch values: 0/1 (e.g. true/false; off/on)
– byte
• a group of 8 bits taken as a single unit
• the smallest unit of memory that is addressable
– word
• A unit of digital information that represents a group of bits that can
be processed as a single unit by a computer's CPU (central
processing unit). The size of a word can vary depending on the
architecture of the computer system, but it is typically 16, 32, or 64
bits in size. Words are often used to represent numerical values or
memory addresses.
• Pentium I, II, III 32 bits (4 bytes)
• Pentium IV 64 bits (8 bytes)
– other units are used, such as blocks, strings, and so on
• these are considered non-standard application structures
Size terminology
• The following prefix terms are used to denote timing interval
size (seconds):
– 10-3 milli
– 10-6 micro
– 10-9 nano
– 10-12 pico
– 10-15 femto
• The following prefix terms are used to denote storage device
size (bytes):
– 210 kilo (1024)
– 220 mega ( ~ 106 )
– 230 giga ( ~ 109 )
– 240 tera ( ~ 1012 )
– 250 peta ( ~ 1015 )
Binary Coding/ Gray Code
• Binary, or base-2, coding is used for all data in the computer
• 2-state switches
– only 0 and 1 are used as values
– each corresponds to a specific electrical (magnetic/optical)
signal value
• Characters
– the ASCII system is used to represent printable characters and
also some non-printable signals used in inter-computer
communication across networks
• Numbers
– unsigned integer
– signed integer
– real, or floating point, numbers
– decimal (base-10) numbers are also used in computers
Unsigned Binary
Unsigned binary is a number system used in computing and digital electronics to
represent non-negative integers using only two digits, 0 and 1. It is called
"unsigned" because it does not use a sign bit to indicate whether a number is
positive or negative.
• Here's an example of an unsigned binary number:
• 10110101
• To convert this binary number to decimal, we can use the method I described
earlier:
10110101 (binary) = 12^7 + 02^6 + 12^5 + 12^4 + 02^3 + 12^2 + 02^1 + 12^0

= 128 + 0 + 32 + 16 + 0 + 4 + 0 + 1

= 181 (decimal)
So, the binary number 10110101 represents the decimal value 181. Note that this
is an unsigned binary number, because it does not include a sign bit to indicate
whether the number is positive or negative.
Unsigned Binary
• We can construct an unsigned binary sequence using the
algorithm
– Build up starting from 0.
– Add 1 to the previous number.
– Repeat previous step until a string of 1’s of length L is reached.
Decimal Binary Binary Code
0 0000 0

1 0001 1

2 0010 10

3 0011 11

4 0100 100

5 0101 101

6 0110 110

7 0111 111

8 1000 1000
Signed Binary - 1’s complement

• In most cases we require both positive and negative integers


• One idea for “designing” negative numbers uses
complementation
– change 0’s to 1’s and 1’s to 0’s

0101

1010
Use of 1's complement
1's complement plays an important role in representing the signed
binary numbers. The main use of 1's complement is to represent a
signed binary number. Apart from this, it is also used to perform
various arithmetic operations such as addition and subtraction.
In signed binary number representation, we can represent both
positive and negative numbers. For representing the positive
numbers, there is nothing to do. But for representing negative
numbers, we have to use 1's complement technique. For
representing the negative number, we first have to represent it with
a positive sign, and then we find the 1's complement of it.
Signed Binary - 2’s complement
• We need a more efficient representation of positive and
negative integers using an L-bit form.
• One straightforward approach is to consider the operation:

X
+Y
0 What representation of Y gives a zero sum?

3 00000011
+ bbbbbbb Y
00000000
Signed Binary - 2’s complement

• We need a more efficient representation of positive and


negative integers using an L-bit form.
• One straightforward approach is to consider the operation:

X
+Y
0 What representation of Y gives a zero sum?

1111111 Carry
3 00000011
-3 + 11111101
1 00000000
Carry out
Signed Binary - 2’s complement
• We need a more efficient representation of positive and
negative integers using an L-bit form.

• The 2’s complement scheme is based on the algorithm:


– 1. Find the 1’s complement
– 2. Add 1 to the result to find the 2’s complement form.

3 00000011
1
~3 11111100
+ 1 2
-3 11111101
Use of 2's complement
• 2's complement is used for representing signed numbers
and performing arithmetic operations such as
subtraction, addition, etc. The positive number is simply
represented as a magnitude form. So there is nothing to
do for representing positive numbers. But if we represent
the negative number, then we have to choose either 1's
complement or 2's complement technique. The 1's
complement is an ambiguous technique, and 2's
complement is an unambiguous technique.
(r-1)’s and r’s complements
• The (r-1)’s complement and r's complement are two methods
of representing negative numbers in binary form.
• The (r-1)’s complement of a binary number is found by
subtracting each digit from the digit base r-1, where r is the
base of the number system. For example, in a binary system
(base 2), the (r-1)’s complement of the binary number 1010
would be:
(2-1) - 1 = 1 - 1 = 0
(2-1) - 0 = 1 - 0 = 1
(2-1) - 1 = 1 - 1 = 0
(2-1) - 0 = 1 - 0 = 1
• So the (r-1)’s complement of 1010 in base 2 is 0101.
(r-1)’s and r’s complements
• The r's complement of a binary number is found by taking the (r-1)’s
complement of the number and then adding 1 to the result. For example,
the r's complement of the binary number 1010 would be:
(2-1) - 1 = 1 - 1 = 0
(2-1) - 0 = 1 - 0 = 1
(2-1) - 1 = 1 - 1 = 0
(2-1) - 0 = 1 - 0 = 1
• So the (r-1)’s complement of 1010 in base 2 is 0101.
• Adding 1 to the (r-1)’s complement gives:
0101 + 1 = 0110
• So the r's complement of 1010 in base 2 is 0110.
Both (r-1)’s complement and r's complement are used to represent negative
numbers in binary arithmetic, with r being the base of the number system. The
main difference between the two is that r's complement is easier to compute
because it requires only one addition operation.
• The main difference between 1's complement and r-1's
complement, and between 2's complement and r's complement is
that r-1's complement and r's complement allow for simpler digital
arithmetic operations, as they only require addition, while 1's
complement and 2's complement require subtraction to perform
negative arithmetic operations. Additionally, r's complement can
represent a wider range of negative numbers than r-1's
complement.
Subtraction of unsigned Numbers
• Problem: Find (M – N) where both M and N are unsigned
numbers in base-r, size L digits.
• Recall that we first learned to do this subtraction using the
concept of “borrowing” – computers can be designed to do
this, but there is a simpler way using r’s complements and
addition

• Example: M > N, L=5 ( M = 72532, N = 13250)

Borrowing: 72532 10’s Compl.: 72532


- 13250 + 86750
59282 159282
Discard Carry

Final Answer: 59282


Floating Point
• Real numbers, both positive and negative, can be represented using
scientific notation. In scientific notation, a real number is written as the
product of a coefficient (also called the significand or mantissa) and a
power of 10, represented by an exponent.
• Examples:

123.456 1.23456 x 102

- 0.000123456 - 1.23456 x 10-2

sign fraction exponent


Binary Coded Decimal (BCD)
• BCD code plays an important role in digital circuits. The BCD stands for
Binary Coded Decimal Number. In BCD code, each digit of the decimal
number is represented as its equivalent binary number. So, the LSB and
MSB of the decimal numbers are represented as its binary numbers. There
are the following steps to convert the binary number to BCD:
1. First, we will convert the binary number into decimal.
2. We will convert the decimal number into BCD.
Binary Coded Decimal (BCD)
Example 1: (11110)2

Steps Binary Number Decimal Number


1) (11110)2 ((1 × 24) + (1 × 23) + (1 × 22) + (1 × 21) + (0 × 20))10
2) (11110)2 (16 + 8 + 4 + 2 + 0)10
3) (11110)2 (30)10

Steps Decimal Number Conversion


Step 1 3010 (0011)2 (0000)2
Step 2 3010 (00110000)BCD
Binary Conversions - Octal, Hexadecimal

• It is important to understand how to convert values from one


to another representation.
• Some conversions are straightforward, while others require
more effort.

• Example: Binary to Octal (base-8)


Octal Digits: 0 1 2 3 4 5 6 7

Binary: 10110001101
Binary Conversions - Octal, Hexadecimal

• It is important to understand how to convert values from one


to another representation.
• Some conversions are straightforward, while others require
more effort.

• Example: Binary to Octal (base-8)


Octal Digits: 0 1 2 3 4 5 6 7

Binary: 10110001101

(Groups of 3 digits, right


Fortofractions,
left) group
bits left to right from
the radix point
Binary Conversions - Octal, Hexadecimal

• It is important to understand how to convert values from one


to another representation.
• Some conversions are straightforward, while others require
more effort.

• Example: Binary to Octal (base-8)


Octal Digits: 0 1 2 3 4 5 6 7

Binary: 10110001101

Convert each group


to an octal digit.
Octal: 2 6 1 5
Binary Conversions - Octal, Hexadecimal

• It is important to understand how to convert values from one


to another representation.
• Some conversions are straightforward, while others require
more effort.

• Example: Binary to Hexadecimal (base-16)


Hexadecimal Digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F

Binary: 10110001101011

Hexadecimal: 2 C 6 B

Convert each group of 4 bits to a hexadecimal digit.


Binary/Decimal Conversions
• Converting to and from binary to decimal requires some
more effort.
• Examples: Decimal integer to Binary

Repeatedly divide quotient by 2 until zero is reached.


Record the remainder for each division:

114
57 0
28 1
14 0
Quotients
7 0 Remainders
3 1
1 1
0 1

1110010
Binary/Decimal Conversions

• Converting binary to/from decimal requires some more


effort.
• Examples: Binary integer to Decimal

• Use the positional representation of the binary string,


multiplying each successive power of 2 by the value of
the binary digit:

1 0 1 1 => 1 x 2 3 + 0 x 22 + 1 x 21 + 1 x 20
Binary/Decimal Conversions
• Converting to and from binary to decimal requires some
more effort.
• Examples: Decimal fraction (0.12) to Binary

Repeatedly multiply by 2, each time “stripping”


the integer digit (0 or 1) and leaving the remaining
fractional product residue.

0.12 x 2 0.24 0 (most significant)


0.24 x 2 0.48 0
0.48 x 2 0.96 0 If a repeating
0.96 x 2 1.92 1 sequence
0.92 x 2 1.84 1 develops, then
0.84 x 2 1.68 1 stop after preset
0.68 x 2 1.36 1 number of digits
0.36 x 2 0.72 0
0.72 x 2 1.44 1 …..

Collect bits: .000111101...


Arithmetic Operations
• Arithmetic operations are mathematical operations that
involve manipulating numerical quantities to produce a result.

• Examples:
– Addition
– Subtraction
– Multiplication
– Division

You might also like