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

Lecture 15 - Data Representation-I

The document covers various aspects of data representation, focusing on binary and hexadecimal numbers, including their conversion to and from decimal. It explains binary addition, integer storage sizes, and signed integers, highlighting the significance of the most and least significant bits. Additionally, it discusses hexadecimal operations such as addition and subtraction, as well as the representation of signed integers.

Uploaded by

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

Lecture 15 - Data Representation-I

The document covers various aspects of data representation, focusing on binary and hexadecimal numbers, including their conversion to and from decimal. It explains binary addition, integer storage sizes, and signed integers, highlighting the significance of the most and least significant bits. Additionally, it discusses hexadecimal operations such as addition and subtraction, as well as the representation of signed integers.

Uploaded by

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

Data Representation

• Binary Numbers
• Translating between binary and decimal
• Binary Addition
• Integer Storage Sizes
• Hexadecimal Integers
• Translating between decimal and
hexadecimal
• Hexadecimal subtraction
• Signed Integers
• Binary subtraction
• Character Storage

21
Binary Numbers

• Digits are 1 and 0


• 1 = true
• 0 = false
• MSB – most significant
bit
• LSB – least significant
MSB LSB
• bit
Bit 10110010100111
00
numbering: 15 0

22
Binary Numbers

• Each digit (bit) is either 1 or 1 1 1 1 1 1 1 1


0 27 26 25 24 23 22 21 20
• Each bit represents a power
of 2:

Every binary
number is a
sum of
powers of 2

23
Translating Binary to Decimal

Weighted positional notation shows how to


calculate the decimal value of each binary bit:
dec = (Dn-1  2n-1)  (Dn-2  2n-2)  ...  (D1  21)  (D0  20)
D = binary digit

binary 00001001 =
decimal 9:
(1  23) + (1  20) = 9 24
Translating Unsigned Decimal to
Binary
• Repeatedly divide the decimal integer by
2. Each remainder is a binary digit in the
translated value:

37.6875 =
100101.1011
25
Exercises

26
Binary Addition
• Starting with the LSB, add each pair of digits,
include the carry if present.

carry:
1
0 0 0 0 0 1 0 0 (4
)
+ 0 0 0 0 0 1 1 1 (7
)

0 0 0 0 1 0 1 1 (11
)
bit 7 6 5 4 3 2 1
position: 0

27
Integer Storage Sizes
byte
8
Standard wor 1
6
d 3
sizes: doublewor
2
6
4
d
quadword

What is the largest unsigned integer that may be stored in


20 bits?

28
Hexadecimal Integers
Binary values are represented in
hexadecimal.

29
Translating Binary to Hexadecimal

• Each hexadecimal digit corresponds to 4


binary bits.
• Example: Translate the binary integer
000101101010011110010100 to
hexadecimal:

30
Converting Hexadecimal to Decimal

• Multiply each digit by its corresponding power


of 16:
dec = (D3  163) + (D2  162) + (D1  161) + (D0  160)

• Hex 1234 equals (1  163) + (2  162) + (3  161) + (4  160), or


decimal 4,660.

• Hex 3BA4 equals (3  163) + (11 * 162) + (10  161) + (4  160), or


decimal 15,268.

31
Powers of 16

Used when calculating hexadecimal values up to


8 digits long:

32
Converting Decimal to
Hexadecimal

decimal 422 = 1A6


hexadecimal

33
Convert Decimal Fraction to Octal
Fraction

34
Hexadecimal Addition

• Divide the sum of two digits by the number base (16). The
quotient becomes the carry value, and the remainder is
the sum digit.
1 1
36 28 6
42
28 45 58 4B
A
78 6D 80 B5

21 / 16 = 1,
rem 5

35
Hexadecimal Subtraction

• When a borrow is required from the digit to the


left, add 16 to the current digit's value:

16 + 5 = 21 – 7 = 14 = E

1
C6 75
A2 47
24 2E

36
Addition and Multiplication
Examples

37
Hexadecimal Complement

38
Signed Integers
The highest bit indicates the sign. 1 =
negative, 0 = positive
sign
bit

1 1 1 1 0 1 1 0
Negativ
e

0 0 0 0 1 0 1 0 Positiv
e

If the highest digit of a hexadecimal integer is > 7,


the value is negative. Examples: 8A, C5, A2, 9D

39
Ranges of Signed Integers

The highest bit is reserved for the sign. This limits


the range:

40

You might also like