0% found this document useful (0 votes)
22 views8 pages

Binary

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

Binary

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

Section 2 − Binary Number System Page 1 of 8

2.1 Binary Numbers


The number system we use is a positional number system meaning that the position of each digit has an associated
weight.
The value of a given number is equivalent to the weighted sum of all its digits. e.g.

1234.5610 = 1×103 + 2×102 + 3×101 + 4×100 + 5×10-1 + 6×10-2

Here, 10 is the base or radix of the number system.


Use a subscript to indicate the radix of the number.
In general
d m −1 d m − 2 d d d
1 0 −1 d − 2 d n =
m −1
∑ di ⋅ ri
i = −n

The leftmost digit is called the most-significant digit (MSD).


The rightmost digit is called the least-significant digit (LSD).

Digital systems use binary digits with a binary radix.

110.1012 = 1×22 + 1×101 + 0×100 + 1×10-1 + 0×10-2 + 1×10-3 = 6.62510

2.3 Number System Conversion

From Binary to Decimal


100010112
= 1×27 + 0×26 + 0×25 + 0×24 + 1×23 + 0×22 + 1×21 + 1×20
= 128 + 8 + 2 + 1

From Decimal to Binary

2 139 1 LSD
2 69 1
2 34 0
2 17 1 13910 = 100010112

2 8 0
2 4 0
2 2 0
1 MSD
Section 2 − Binary Number System Page 2 of 8

2.2 Octal and Hexadecimal Numbers


Binary numbers are too long to write so we use a shorthand notation:
Octal – base 8; needs 8 different values; 0 to 7.
Hexadecimal – base 16; needs 16 different values; 0 to 9, A to F.

Binary (radix 2) Octal (radix 8) Decimal (radix 10) Hexadecimal (radix 16)
0000 0 0 0
0001 1 1 1
0010 2 2 2
0011 3 3 3
0100 4 4 4
0101 5 5 5
0110 6 6 6
0111 7 7 7
1000 10 8 8
1001 11 9 9
1010 12 10 A
1011 13 11 B
1100 14 12 C
1101 15 13 D
1110 16 14 E
1111 17 15 F

2.3 Number System Conversion

From Binary to Octal


Starting at the binary point, separate the bits into groups of three and replace each group with the corresponding
octal digit.

100010112 = 010 001 011 = 2138

11.101112 = 011 . 101 110 = 3.568

From Octal to Binary


Replace each octal digit with the corresponding 3-bit binary string.

2138 = 010 001 011 = 100010112

From Binary to Hexadecimal


Starting at the binary point, separate the bits into groups of four and replace each group with the corresponding
hexadecimal digit.

100010112 = 1000 1011 = 8B16

11.101112 = 0011 . 1011 1000 = 3.B816

From Hexadecimal to Binary


Replace each hexadecimal digit with the corresponding 4-bit binary string.

8B16 = 1000 1011 = 100010112


Section 2 − Binary Number System Page 3 of 8

From Octal to Decimal


52218
= 5×83 + 2×82 + 2×81 + 1×80
= 2560 + 128 + 16 + 1
= 270510

From Decimal to Octal

8 2705 1 LSD
8 338 2 270510 = 52218
8 42 2
5 MSD

From Hexadecimal to Decimal


A9C16
= 10×162 + 9×161 + 12×160
= 2560 + 144 + 12
= 271610

From Decimal to Hexadecimal

16 2716 C LSD
271610 = A9C16
16 169 9
A MSD

Examples:
Binary Octal Decimal Hex
10011010 232 154 9A
10111000101 2705 1477 5C5
101010010001 5221 2705 A91
1110111100 1674 956 3BC
Section 2 − Binary Number System Page 4 of 8

2.4 Add
1 1 1 1 1 0 0 1 1
+ 1 0 0 1 + 1 1 1 0
1 1 0 0 0 1 0 0 0 0 1

2.4 Subtract
1 1 0 0 0 1 0 0 1 1
− 1 1 1 1 − 1 1 1 1
1 0 0 1 1 0 0

2.7 Multiply
normally for implementation - add the shifted
multiplicands one at a time.
1 1 1 0 = 14 1 1 1 0
* 1 1 0 1 = 13 * 1 1 0 1
1 1 1 0 1 1 1 0
0 0 0 0 + 0 0 0 0
1 1 1 0 0 1 1 1 0
+ 1 1 1 0 + 1 1 1 0
1 0 1 1 0 1 1 0 1 0 0 0 1 1 0
+ 1 1 1 0
1 0 1 1 0 1 1 0 (8 bits)
Section 2 − Binary Number System Page 5 of 8

2.8 Divide
1 1 0 1 1 1 0
1 1 1 1 ) 1 1 0 0 0 1 0 1 | 1 1 0 1 ) 1 0 1 1 0 0 1 |
1 1 1 1 | 1 1 0 1 |
1 0 0 1 1 0 1 | 1 0 0 1 0 1 |
1 1 1 1 | 1 1 0 1 |
1 0 0 0 1 | 1 0 1 1 |
0 0 0 0 | 0 0 0 0 |
1 0 0 0 1 | 1 0 1 1
1 1 1 1 |
1 0

1 0 0 1
1 1 0 1 ) 1 1 1 1 0 0 1 |
1 1 0 1 |
1 0 0 0 1 |
0 0 0 0 |
1 0 0 0 1 |
0 0 0 0 |
1 0 0 0 1 |
1 1 0 1 |
1 0 0
Section 2 − Binary Number System Page 6 of 8

2.5 Representation of Negative Numbers

Sign-Magnitude
The most significant bit is the sign bit and the rest of the number is the magnitude.
0 = positive
1 = negative
n bit range = -(2n-1-1) to +(2n-1-1)
4 bits range = -7 to +7
2 possible representation of zero, “+0” and “-0”.

2's Complement
flip bits and add one.
n bit range = -(2n-1) to +(2n-1-1)
4 bits range = -8 to +7

0000 =0
0001 =1
0010 =2
0011 =3
0100 =4
0101 =5
0110 =6
0111 =7
1000 = -8
1001 = -7
1010 = -6
1011 = -5
1100 = -4
1101 = -3
1110 = -2
1111 = -1

Example

0110 =6
1001 flip bits
1010 add one = -6

1110 = 14
0001 flip bits
0010 add one WRONG this is not -14. Out of range. Need 5 bits

01110 = 14
10001 flip bits
10010 add one. This is -14.

Sign Extend
add 0 for positive numbers
add 1 for negative numbers
Section 2 − Binary Number System Page 7 of 8

Add 2's Complement


1 1 1 0 = -2 1 1 1 0 = -2
+ 1 1 0 1 = -3 + 0 0 1 1 =3
1 1 0 1 1 ignore carry = -5 1 0 0 0 1 ignore carry = 1
Be careful of overflow errors. An addition overflow occurs whenever the sign of the sum is different from the signs
of both operands. Ex.
0 1 0 0 =4 1 1 0 0 = -4
+ 0 1 0 1 =5 + 1 0 1 1 = -5
1 0 0 1 = -7 WRONG 1 0 1 1 1 ignore carry = 7 WRONG
Subtract 2's Complement
0 0 1 0 =2
+ 1 1 1 0 = -2
1 0 0 0 0 ignore carry = 0

Multiply 2's Complement

1 1 1 0 = -2 1 1 1 0 = -2
* 1 1 0 1 = -3 * 0 0 1 1 =3
1 1 1 1 1 1 1 0 sign extend to 8 bits 1 1 1 1 1 1 1 0 sign extend to 8 bits
+ 0 0 0 0 0 0 0 +1 1 1 1 1 1 0
1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 0 ignore carry = -6
+ 1 1 1 1 1 0
1 1 1 1 1 0 1 1 0 ignore carry
+ 0 0 0 1 0 negate -2 for sign bit
1 0 0 0 0 0 1 1 0 ignore carry = 6

1 0 0 1 0 = -14
* 1 0 0 1 1 = -13
1 1 1 1 1 1 0 0 1 0 sign extend to 10 bits
+ 1 1 1 1 1 0 0 1 0
1 1 1 1 1 0 1 0 1 1 0 ignore carry
+ 0 0 0 0 0 0 0 0
1 1 1 1 0 1 0 1 1 0
+ 0 0 0 0 0 0 0
1 1 1 1 0 1 0 1 1 0
+ 0 0 1 1 1 0 negate -14 for sign bit
1 0 0 1 0 1 1 0 1 1 0 ignore carry = 182
Section 2 − Binary Number System Page 8 of 8

2.9 Floating-Point Numbers


mantissa x (radix)exponent
The floating-point representation always gives us more range and less precision than the fixed-point
representation when using the SAME number of digits.

Mantissa Sign
Mantissa magnitude
sign exponent
General format
0 1 9 31
Mantissa 8-bit excess-127
23-bit normalized fraction
sign characteristic
32-bit standard Implied binary point
0 1 12 63
Mantissa 11-bit excess
52-bit normalized fraction
sign 1023 charactstic
64-bit standard
Normalized fraction - the fraction always starts with a nonzero bit. e.g.

0.01 … x 2e would be normalized to 0.1 … x 2e-1


1.01 … x 2e would be normalized to 0.101 … x 2e+1

Since the only nonzero bit is 1, it is usually omitted in all computers today. Thus, the 23-bit normalized fraction
in reality has 24 bits.

The exponent is represented in a biased form.


• If we take an m-bit exponent, there are 2m possible unsigned integer values.
• Re-label these numbers: 0 to 2m-1 → -2m-1 to 2m-1-1 by subtracting a constant value (or bias) of 2m-1 (or
sometimes 2m-1-1).
• Ex. using m=3, the bias = 23-1 = 4. Thus the series 0,1,2,3,4,5,6,7 becomes -4,-3,-2,-1,0,1,2,3. Therefore, the
true exponent -4 is represented by 0 in the bias form and -3 by +1, etc.
• zero is represented by 0.0 … x 20.
Ex. if n = 1010.1111, we normalize it to 0.10101111 x 24. The true exponent is +4. Using the 32-bit standard
and a bias of 2m-1-1 = 28-1-1 = 127, the true exponent (+4) is stored as a biased exponent of 4+127 = 131, or
10000011 in binary. Thus we have
0|10000011|01011110000000000000000
Notice that the first 1 in the normalized fraction is omitted.

The biased exponent representation is also called excess n, where n is 2m-1-1 (or 2m-1).

2.10 Binary Coded Decimals (BCD)

2.11 Character Codes (ASCII – The American Standard Code for Information Interchange)

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