0% found this document useful (0 votes)
68 views15 pages

COA Chapter 2

The document discusses data representation in binary format. It defines common binary terminology like bit, nibble, byte, word, and double word. It explains binary number systems like binary, octal, and hexadecimal. It describes various methods for converting between decimal, binary, octal, and hexadecimal numbers including division/multiplication methods. It also discusses representation of negative numbers using sign-and-magnitude, 1's complement, and 2's complement methods and how addition and subtraction are performed using complements.

Uploaded by

Chala Geta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views15 pages

COA Chapter 2

The document discusses data representation in binary format. It defines common binary terminology like bit, nibble, byte, word, and double word. It explains binary number systems like binary, octal, and hexadecimal. It describes various methods for converting between decimal, binary, octal, and hexadecimal numbers including division/multiplication methods. It also discusses representation of negative numbers using sign-and-magnitude, 1's complement, and 2's complement methods and how addition and subtraction are performed using complements.

Uploaded by

Chala Geta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Chapter 2

Data Representation

Binary Terminology

When writing values in decimal, it is common to separate the places or positions of large
numbers in groups of three digits separated by commas. For example, 34532374510 is typically
written 345,323,74510 showing that there are 345 millions, 323 thousands, and 745 ones. This
practice makes it easier to read and comprehend the magnitude of the numbers. Binary numbers
are also divided into components depending on their application. Each binary grouping has been
given a name.

To begin with, a single place or position in a binary number is called a bit, short for binary digit.
For example, the binary number 01102 is made up of four bits. The rightmost bit, the one that
represents the ones place, is called the Least Significant Bit or LSB. The leftmost bit, the one
that represents the highest power of two for that number, is called the Most Significant Bit or
MSB. Note that the MSB represents a bit position. It doesn't mean that a '1' must exist in that
position.

The next four terms describe how bits might be grouped together.

Nibble – A four bit binary number

Byte – A unit of storage for a single character, typically an eight bit (2 nibble) binary number
(short for binary term)

Word – Typically a sixteen bit (2 byte) binary number

Double Word – A thirty-two bit (2 words) binary number

The following are some examples of each type of binary number.

Bit 12

Nibble 10102

Byte 101001012

Word 10100101111100002

Double Word 101001011111000011001110111011012


Weighted-positional notation

 Decimal number system, symbols = { 0, 1, 2, 3, …, 9 }


 Position is important
 Example:(7594)10 = (7x103) + (5x102) + (9x101) + (4x100)
 The value of each symbol is dependent on its type and its position in the number
 In general, (anan-1… a0)10 = (an x 10n) + (an-1 x 10n-1) + … + (a0 x 100)
 Fractions are written in decimal numbers after the decimal point.
 (2.75)10 = (2 x 100) + (7 x 10-1) + (5 x 10-2)

In general, (anan-1… a0 . f1f2 … fm)10 = (an x 10n) + (an-1x10n-1) + … + (a0 x 100) + (f1 x 10-1) + (f2 x
10-2) + … + (fm x 10-m)

Base R- to decimal conversion

 Binary (base 2): weights in powers-of-2.


o Binary digits (bits): 0, 1.
 Octal (base 8): weights in powers -of-8.
o Octal digits: 0, 1,2,3,4,5,6,7.
 Hexadecimal (base 16): weights in powers-of-16.
o Hexadecimal digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
 Base R: weights in powers-of-R.
 (1101.101)2 = 1 23 + 1 22 + 1 20 + 1 2-1 + 1 2-3= 8 + 4 + 1 + 0.5 + 0.125 =
(13.625)10
 (572.6)8 = 5 82 + 7 81 + 2 80 + 6 8-1 = 320 + 56 + 16 + 0.75 = (392.75)10
 (2A.8)16 = 2 161 + 10 160 + 8 16-1 = 32 + 10 + 0.5 = (42.5)10
 (341.24)5 = 3 52 + 4 51 + 1 50 + 2 5-1 + 4 5-2 = 75 + 20 + 1 + 0.4 + 0.16 =
(96.56)10

Decimal-to-Binary Conversion

Step 1: Break the number in two parts: Whole number and fraction part.
Step 2: Repeated Division-by-2 Method (for whole numbers)

Step 3: Repeated Multiplication-by-2 Method (for fractions)

 To convert a whole number to binary, use successive division by 2 until the quotient is 0.
The remainders form the answer, with the first remainder as the least significant bit
(LSB) and the last as the most significant bit (MSB). (43)10 = (101011)2

2 43

2 21 rem 1  LSB

2 10 rem 1

2 5 rem 0

2 2 rem 1

2 1 rem 0

0 rem 1  MSB

 To convert decimal fractions to binary, repeated multiplication by 2 is used, until the


fractional product is 0 (or until the desired number of decimal places). The carried digits,
or carries, produce the answer, with the first carry as the MSB, and the last as the LSB.

E.g. (0.3125)10 = (.0101)2

Summary: Conversion between Bases

 Base-R to decimal: multiply digits with their corresponding weights


 Decimal to binary (base 2)
o whole numbers: repeated division-by-2
o fractions: repeated multiplication-by-2
 Decimal to base-R
o whole numbers: repeated division-by-R
o fractions: repeated multiplication-by-R

Binary-Octal/Hexadecimal Conversion

 Binary  Octal: Partition in groups of 3

(10 111 011 001 . 101 110)2 = (2731.56)8

 Octal  Binary: reverse

(2731.56)8 = (10 111 011 001 . 101 110)2

 Binary  Hexadecimal: Partition in groups of 4

(101 1101 1001 . 1011 1000)2 = (5D9.B8)16

 Hexadecimal  Binary: reverse

(5D9.B8)16 = (101 1101 1001 . 1011 1000)2

Negative Numbers: Sign-and-Magnitude

 Negative numbers are usually written by prep-ending a minus sign in front.


 Example:

- (12)10, - (1100)2

 In computer memory of fixed width, this sign is usually represented by a bit:

0 for +

1 for -

There are three common ways of representing signed numbers:


 Sign-And-Magnitude
 1s complement
 2s complement

Negative Numbers: Sign-and-Magnitude

 Example: an 8-bit number can have 1-bit sign and 7-bits magnitude.

 Largest Positive Number: 0 1111111 +(127)10


 Largest Negative Number: 1 1111111 -(127)10
 Zeroes: 0 0000000 +(0)10

1 0000000 -(0)10

 Range: -(127)10 to +(127)10


 To negate a number, just invert the sign bit.
 Examples: - (0 0100001)= (1 0100001)
o (1 0000101) = (0 0000101)

1s and 2s complement notations

 In these notations, a positive number is represented as it is (like an unsigned positive


number)
 A negative number, however, is represented by taking the complement of unsigned
number
 1s complement of an unsigned number is obtained by inverting all the bits of the number

Examples: 1s complement of (00000001)2 is (11111110)1s


1s complement of (01111111)2 = (10000000)1s

 1s representation of the number in 8-bits

Example:

 (+14)10 = (00001110)2 = (00001110)1s


 (-14)10 = -(00001110)2 = (11110001)1s

For 8-bits number system:

 Largest Positive Number: 0 1111111 +(127)10


 Largest Negative Number: 1 0000000 -(127)10
 Zeroes: 0 0000000

1 1111111

 Range: -(127)10 to +(127)10


 The most significant bit still represents the sign:

0 = +ve; 1 = -ve.

 Given a number x which can be expressed as an n-bit binary number, its negative value
can be obtained in 1s-complement representation using:

- x = 2n - x - 1

Example: With an 8-bit number 00001100, its negative value, expressed in 1s


complement, is obtained as follows:

-(00001100)2 = - (12)10

= (28 - 12 - 1)10

= (243)10
= (11110011)1s

2s Complement

 2s complement of an unsigned number is obtained by inverting all the bits and adding 1.

Examples:

1) 2s complement of (00000001)2 = (11111110)1s (invert)

= (11111111)2s (add 1)

2) 2s complement of (01111110)2 = (10000001)1s (invert)

= (10000010)2s (add 1)

 2s complement representation for 8 bit numbers:

Example:

 (+14)10 = (00001110)2 = (00001110)2s


 (-14)10 = -(00001110)2 = (11110010)2s
 Given a number x which can be expressed as an n-bit binary number, its negative number
can be obtained in 2s-complement representation using: - x = 2n - x

Example: With an 8-bit number 00001100, its negative value in 2s complement is


thus:

-(00001100)2 = - (12)10

= (28 - 12)10

= (244)10

= (11110100)2s
Complements

 Complement numbers can help perform subtraction.

With complements, subtraction can be performed by addition.

 In general for Base-r number, there are:

(i) Diminished Radix (or r-1’s) Complement

(ii) Radix (or r’s) Complement

 For Base-2 number, we have seen:

(i) 1s Complement

(ii) 2s Complement

Use of complements

 Complement number system is used to minimize the amount of circuitry needed to


perform integer arithmetic.
 For example, A-B can be performed by computing A + (-B), where (-B) is represented in
2s complement of B.

Hence, the computer needs only binary adder and complementing circuit to
handle both addition and subtraction

 Signed binary numbers are a fixed range.


 If the result of addition/subtraction goes beyond this range, overflow occurs.
 Two conditions under which overflow can occur are:

(i) Positive add positive gives negative


(ii) Negative add negative gives positive

2s complement addition

Algorithm:

 Perform binary addition on the two numbers.


 Ignore the carry out of the MSB.

Check for overflow: Overflow occurs if the carrier into and out of the MSB are
different.

2s complement subtraction

Algorithm for performing A - B:

A-B = A + (-B)

 Take 2s complement of B by inverting all the bits and adding 1


 Add the 2s complement of B to A

Examples: 2s addition/Subtraction
4-bits system:

Examples: Overflow in 2s addition/Subtraction


4-bits system
 

Fixed Point Numbers

 The signed and unsigned numbers representation given are fixed point numbers.
 The binary point is assumed to be at a fixed location, say, at the end of the number:

 can represent all integers between -128 to 127 (for 8 bits).

 In general, other locations for binary points possible.

 Examples: If two fractional bits are used, we can represent:

(001010.11)2s = (10.75)10

(111110.11)2s = -(000001.01)2

= -(1.25)10
 Fixed point numbers have limited range.
 To represent very large or very small numbers, we use floating point numbers (cf.
scientific numbers). Examples:

0.23 x 1023 (very large positive number)

-0.1239 x 10-10 (very small negative number)

 Floating point numbers have three parts:

mantissa, base, and exponent

 Base is usually fixed for each number system.

Therefore, needs only mantissa and exponent. 

 Mantissa is usually in normalised form:

(base 10) 23 x 1021 normalised to 0.23 x 1023

(base 10) -0.0017 x 1021 normalised to -0.17 x 1019

(base 2) 0.01101 x 23 normalised to 0.1101 x 22

 A 16-bit floating point number may have 10-bit mantissa and 6-bit exponent.
 More bits in exponent gives larger range.
 More bits for mantissa gives better precision.
 Arithmetic is more difficult for floating point numbers.
 MULTIPLICATION

Steps: (i) multiply the mantissa

(ii) add-up the exponents


(iii) normalise

 Example:

(0.12 x 102)10 x (0.2 x 1030)10

= (0.12 x 0.2)10 x 102+30

= (0.024)10 x 1032 (normalise)

= (0.24 x 1031)10

 ADDITION

Steps: (i) equalise the exponents

(ii) add-up the mantissa

(iii) normalise

 Example:

(0.12 x 103)10 + (0.2 x 102)10

= (0.12 x 103)10 + (0.02 x 103)10 (equalize exponents)

= (0.12 + 0.02)10 x 103 (add mantissa)

= (0.14 x 103)10

Binary Coded Decimal (BCD)

Decimal numbers are more natural to humans. Binary numbers are natural to
computers. Quite expensive to convert between the two.

 If little calculation is involved, we can use some coding schemes for decimal numbers.
 One such scheme is BCD, also known as the 8421 code.
 Represent each decimal digit as a 4-bit binary code.

Decimal digit 0 1 2 3 4

BCD 0000 0001 0010 0011 0100

Decimal digit 5 6 7 8 9

BCD 0101 0110 0111 1000 1001

 Some codes are unused, eg: (1010)BCD, (1011) BCD, …, (1111) BCD. These codes are
considered as errors.
 Easy to convert, but arithmetic operations are more complicated.
 Suitable for interfaces such as keypad inputs and digital readouts.
 Examples:

(234)10 = (0010 0011 0100)BCD

(7093)10 = (0111 0000 1001 0011)BCD

(1000 0110)BCD = (86)10

(1001 0100 0111 0010)BCD = (9472)10

Notes: BCD is not equivalent to binary.

Example: (234)10 = (11101010)2

Alphanumeric codes

 Apart from numbers, computers also handle textual data.


 Character set frequently used includes:

alphabets: ‘A’ .. ‘Z’, and ‘a’ .. ‘z’


digits: ‘0’ .. ‘9’

special symbols: ‘$’, ‘.’, ‘,’, ‘@’, ‘*’, …

non-printable: SOH, NULL, BELL, …

 Usually, these characters can be represented using 7 or 8 bits.

Two widely used standards:

ASCII (American Standard Code for Information Interchange)

EBCDIC (Extended BCD Interchange Code)

 ASCII: 7-bit, plus a parity bit for error detection (odd/even parity).
 EBCDIC: 8-bit code

Error Detection Codes

 Errors can occur data transmission. They should be detected, so that re-transmission can
be requested.
 With binary numbers, usually single-bit errors occur.

Example: 0010 erroneously transmitted as 0011, or 0000, or 0110, or


1010.

 For single-error detection, one additional bit is needed.


 Parity bit.
o Even parity: additional bit supplied to make total number of ‘1’s even.
o Odd parity: additional bit supplied to make total number of ‘1’s odd.
 Example: Odd parity.
 Parity bit can detect odd number of errors but not even number of errors.

Example: For odd parity numbers,


10011  10001 (detected)

10011  10101 (non detected)

 Parity bits can also be applied to a block of data:


 Sometimes, it is not enough to do error detection. We may want to do error correction.
Error correction can be done but is more expensive.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy