Number Systems

Download Report

Transcript Number Systems

1. Number Systems
Location in
course textbook
Chapt. 2
Quantities/Counting (1 of 3)
Decimal
Binary
Octal
Hexadecimal
0
0
0
0
1
1
1
1
2
10
2
2
3
11
3
3
4
100
4
4
5
101
5
5
6
110
6
6
7
111
7
7
p. 33
Quantities/Counting (2 of 3)
Decimal
Binary
Octal
Hexadecimal
8
1000
10
8
9
1001
11
9
10
1010
12
A
11
1011
13
B
12
1100
14
C
13
1101
15
D
14
1110
16
E
15
1111
17
F
Quantities/Counting (3 of 3)
Decimal
Binary
Octal
Hexadecimal
16
10000
20
10
17
10001
21
11
18
10010
22
12
19
10011
23
13
20
10100
24
14
21
10101
25
15
22
10110
26
16
23
10111
27
17
Etc.
Conversion Among Bases
 The possibilities:
Decimal
Octal
Binary
Hexadecimal
pp. 40-46
Quick Example
2510 = 110012 = 318 = 1916
Base
Decimal to Decimal (just for fun)
Decimal
Octal
Binary
Hexadecimal
Next slide…
Weight
12510 =>
5 x 100
2 x 101
1 x 102
Base
=
5
= 20
= 100
125
Binary to Decimal
Decimal
Octal
Binary
Hexadecimal
Binary to Decimal
 Technique



Multiply each bit by 2n, where n is the “weight”
of the bit
The weight is the position of the bit, starting
from 0 on the right
Add the results
Example
Bit “0”
1010112 =>
1
1
0
1
0
1
x
x
x
x
x
x
20
21
22
23
24
25
=
=
=
=
=
=
1
2
0
8
0
32
4310
Octal to Decimal
Decimal
Octal
Binary
Hexadecimal
Octal to Decimal
 Technique



Multiply each bit by 8n, where n is the “weight”
of the bit
The weight is the position of the bit, starting
from 0 on the right
Add the results
Example
7248 =>
4 x 80 =
2 x 81 =
7 x 82 =
4
16
448
46810
Hexadecimal to Decimal
Decimal
Octal
Binary
Hexadecimal
Hexadecimal to Decimal
 Technique



Multiply each bit by 16n, where n is the
“weight” of the bit
The weight is the position of the bit, starting
from 0 on the right
Add the results
Example
ABC16 =>
C x 160 = 12 x
1 =
12
B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
Decimal to Binary
Decimal
Octal
Binary
Hexadecimal
Decimal to Binary
 Technique




Divide by two, keep track of the remainder
First remainder is bit 0 (LSB, least-significant
bit)
Second remainder is bit 1
Etc.
Example
12510 = ?2
2 125
2 62
2 31
2 15
7
2
3
2
1
2
0
1
0
1
1
1
1
1
12510 = 11111012
Octal to Binary
Decimal
Octal
Binary
Hexadecimal
Octal to Binary
 Technique

Convert each octal digit to a 3-bit equivalent
binary representation
Example
7058 = ?2
7
0
5
111 000 101
7058 = 1110001012
Hexadecimal to Binary
Decimal
Octal
Binary
Hexadecimal
Hexadecimal to Binary
 Technique

Convert each hexadecimal digit to a 4-bit
equivalent binary representation
Example
10AF16 = ?2
1
0
A
F
0001 0000 1010 1111
10AF16 = 00010000101011112
Decimal to Octal
Decimal
Octal
Binary
Hexadecimal
Decimal to Octal
 Technique


Divide by 8
Keep track of the remainder
Example
123410 = ?8
8
8
8
8
1234
154
19
2
0
2
2
3
2
123410 = 23228
Decimal to Hexadecimal
Decimal
Octal
Binary
Hexadecimal
Decimal to Hexadecimal
 Technique


Divide by 16
Keep track of the remainder
Example
123410 = ?16
16
16
16
1234
77
4
0
2
13 = D
4
123410 = 4D216
Binary to Octal
Decimal
Octal
Binary
Hexadecimal
Binary to Octal
 Technique


Group bits in threes, starting on right
Convert to octal digits
Example
10110101112 = ?8
1 011 010 111
1
3
2
7
10110101112 = 13278
Binary to Hexadecimal
Decimal
Octal
Binary
Hexadecimal
Binary to Hexadecimal
 Technique


Group bits in fours, starting on right
Convert to hexadecimal digits
Example
10101110112 = ?16
10 1011 1011
2
B
B
10101110112 = 2BB16
Octal to Hexadecimal
Decimal
Octal
Binary
Hexadecimal
Octal to Hexadecimal
 Technique

Use binary as an intermediary
Example
10768 = ?16
1
0
7
6
001
000
111
110
2
3
E
10768 = 23E16
Hexadecimal to Octal
Decimal
Octal
Binary
Hexadecimal
Hexadecimal to Octal
 Technique

Use binary as an intermediary
Example
1F0C16 = ?8
1
0001
1
F
0
1111
7
C
0000
4
1100
1
4
1F0C16 = 174148
Exercise – Convert ...
Decimal
Binary
Octal
Hexadecimal
33
1110101
703
1AF
Don’t use a calculator!
Skip answer
Answer
Exercise – Convert
Answer …
Decimal
Binary
Octal
Hexadecimal
33
100001
41
21
117
1110101
165
75
451
111000011
703
1C3
431
110101111
657
1AF
Common Powers (1 of 2)
 Base 10
Power
Preface
Symbol
Value
10-12
pico
p
.000000000001
10-9
nano
n
.000000001
10-6
micro

.000001
10-3
milli
m
.001
103
kilo
k
1000
106
mega
M
1000000
109
giga
G
1000000000
1012
tera
T
1000000000000
Common Powers (2 of 2)
 Base 2
Power
Preface
Symbol
Value
210
kilo
k
1024
220
mega
M
1048576
230
Giga
G
1073741824
• What is the value of “k”, “M”, and “G”?
• In computing, particularly w.r.t. memory,
the base-2 interpretation generally applies
Example
In the lab…
1. Double click on My Computer
2. Right click on C:
3. Click on Properties
/ 230 =
Exercise – Free Space
 Determine the “free space” on all drives on a
machine in the lab
Free space
Drive
A:
C:
D:
E:
etc.
Bytes
GB
Review – multiplying powers
 For common bases, add powers
ab  ac = ab+c
26  210 = 216 = 65,536
or…
26  210 = 64  210 = 64k
Binary Addition (1 of 2)
 Two 1-bit values
A
0
0
B
0
1
A+B
0
1
1
1
0
1
1
10
“two”
pp. 36-38
Binary Addition (2 of 2)
 Two n-bit values



Add individual bits
Propagate carries
E.g.,
1
1
10101
+ 11001
101110
21
+ 25
46
Multiplication (1 of 3)
 Decimal (just for fun)
35
x 105
175
000
35
3675
pp. 39
Multiplication (2 of 3)
 Binary, two 1-bit values
A
0
0
B
0
1
AB
0
0
1
1
0
1
0
1
Multiplication (3 of 3)
 Binary, two n-bit values


As with decimal values
E.g.,
1110
x 1011
1110
1110
0000
1110
10011010
Fractions
 Decimal to decimal (just for fun)
3.14 =>
4 x 10-2 = 0.04
1 x 10-1 = 0.1
3 x 100 = 3
3.14
pp. 46-50
Fractions
 Binary to decimal
10.1011 =>
1
1
0
1
0
1
x
x
x
x
x
x
2-4
2-3
2-2
2-1
20
21
=
=
=
=
=
=
0.0625
0.125
0.0
0.5
0.0
2.0
2.6875
pp. 46-50
Fractions
 Decimal to binary
3.14579
11.001001...
.14579
x
2
0.29158
x
2
0.58316
x
2
1.16632
x
2
0.33264
x
2
0.66528
x
2
1.33056
etc.
p. 50
Exercise – Convert ...
Decimal
Binary
Octal
Hexadecimal
29.8
101.1101
3.07
C.82
Don’t use a calculator!
Skip answer
Answer
Exercise – Convert
Answer …
Decimal
Binary
Octal
Hexadecimal
29.8
11101.110011…
35.63…
1D.CC…
5.8125
101.1101
5.64
5.D
3.109375
11.000111
3.07
3.1C
12.5078125
1100.10000010
14.404
C.82
Binary Coded Decimal (BCD)
•
•
Representing one decimal number at a time
How can we represent the ten decimal numbers (0-9) in binary code?
Numeral
0
1
2
3
4
5
6
7
8
9


BCD Representation
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
We can represent any integer by a string of binary digits.
For example, 749 can be represented in binary as: 011101001001
How Many Bits Are Necessary to
Represent Something?










1 bit can represent two (21) symbols
 either a 0 or a 1
2 bits can represent four (22) symbols
 00 or 01 or 10 or 11
3 bits can represent eight (23) symbols
 000 or 001 or 011 or 111 or 100 or 110 or 101 or 010
4 bits can represent sixteen (24) symbols
5 bits can represent 32 (25) symbols
6 bits can represent 64 (26) symbols
7 bits can represent 128 (27) symbols
8 bits (a byte) can represent 256 (28) symbols
n bits can represent (2n) symbols!
So…how many bits are necessary for all of us in class to have a unique
binary ID? Are two bits enough? Three? Four? Five? Six? Seven?
63
Binary Codes
A binary code is a group of n bits that
assume up to 2n distinct combinations of 1’s
and 0’s with each combination representing
one element of the set that is being coded.
64
Binary Digital Codes
• Gray Code
– Gray Code
• BCD 2421
– BCD 2421 code
• BCD XS 3 – BCD Excess 3 code
• BCD 8421 – BCD 8421 code
• EBCDIC – Extended BCD Interchange Code
65
BCD – Binary Coded Decimal
BCD is a convention for mapping binary
numbers to decimal numbers.
 When the decimal numbers are represented in
BCD, each decimal digit is represented by the
equivalent BCD code.
 Example :BCD Representation of Decimal
6349

6
3
4
9
0110 0011 0100 1001
66
BCD – Binary Coded Decimal
Decimal
Number
BCD
Number
0
1
2
3
4
5
6
7
8
9
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
67
EXCESS 3 CODE
 The excess-3 code is obtained by adding 3
(0011) to the corresponding BCD
equivalent binary number.
 Excess-3 have a self-complementing
property
68
EXCESS 3 CODE
Decimal
Number
0
1
2
3
4
5
6
7
8
9
BCD
Excess-3
Number Number
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
69
BCD-to-Excess-3 Table
70
BCD – Binary Coded Decimal
Decimal
Number
10
121
234
1003
BCD
Number
0001 0000
0001 0010 0001
0010 0011 0100
0001 0000 0000 0011
71
BCD 2421 CODE
 2421 and excess-3 have a self-complementing
property


9’s complement is obtained by 1’s to 0’s and 0’s to
1’s.
Useful property when doing arithmetic operations
with signed complement representation.
 This code is widely used in instruments and
electronic calculators.
72
GRAY CODE






Unweighted and is not an arithmetic code
Only one bit changes from one code to the next in the
sequence
Gray code can be any amounts of bits.
The gray code originated when digital logic circuits
were built from vacuum tubes and electromechanical
relays
Counters generated tremendous power demands and
noise spikes when many bits changed at once
Using gray code counters, any increment or
decrement changed only one bit
73
DECIMAL BINARY GRAY CODE
GRAY CODE
0
0000
0000
1
0001
0001
2
0010
0011
3
0011
0010
4
0100
0110
5
0101
0111
6
0110
0101
7
0111
0100
8
1000
1100
9
1001
1101
10
1010
1111
11
1011
1110
12
1100
1010
13
1101
1011
14
1110
1001
15
1111
1000
VARIOUS DECIMAL CODES
75
Sign Magnitude
 An extra bit in the most significant position is
designated as the sign bit which is to the left
of an unsigned integer. The unsigned integer
is the magnitude.
xxx xxxx
x
 A 0 in the sign bit means positive, and a 1
means negative
Sign Extension - complement
 For positive number, a 0 is used to stuff the
remaining positions.
0xxxxxxx
The original number is
placed into the least
significant portion
000000000xxxxxxx
 For negative number, a 1 is used to stuff the
remaining positions.
1xxxxxxx
111111111xxxxxxx
The original number is
placed into the least
significant portion
9’s complement Examples
2- Find the 9’s complement of 546700 and
12389
The 9’s complement of 546700 is 999999 546700= 453299
and the 9’s complement of 12389 is
99999- 12389 = 87610.
-
-
9
9
9
9
9
9
5
4
6
7
0
0
4
5
3
2
9
9
9
9
9
9
9
1
2
3
8
9
8
7
6
1
0
l’s complement
 For binary numbers, r = 2 and r — 1 = 1,
 r-1’s complement is the l’s complement.
 The l’s complement of N is (2n - 1) - N.
-
Bit n-1
Bit n-2
…….
Bit 1
Bit 0
1
1
1
1
1
Digit
n
Digit
n-1
Next
digit
Next
digit
First
digit
l’s complement
Find r-1 complement for binary number N with four binary digits.
r-1 complement for binary means 2-1 complement or 1’s complement.
n = 4, we have 24 = (10000)2 and 24 - 1 = (1111)2.
The l’s complement of N is (24 - 1) - N. = (1111) - N
l’s complement
The complement 1’s of
1011001 is 0100110
The 1’s complement of
0001111 is 1110000
-
-
1
1
1
1
1
1
1
1
0
1
1
0
0
1
0
1
0
0
1
1
0
1
1
1
1
1
1
1
0
0
0
1
1
1
1
1
1
1
0
0
0
0
10’s complement Examples
Find the 10’s complement of
546700 and 12389
0
0
0
0
0
0
5
4
6
7
0
0
and the 10’s complement of
12389 is
4
5
3
3
0
0
100000 - 12389 = 87611.
1
0
0
0
0
0
1
2
3
8
9
8
7
6
1
1
The 10’s complement of 546700
is 1000000 - 546700= 453300
Notice that it is the same as 9’s
complement + 1.
1
-
-
2’s complement
For binary numbers, r = 2,
r’s complement is the 2’s complement.
The 2’s complement of N is 2n - N.
1
-
0
0
0
0
0
Digit
n
Digit
n-1
Next
digit
Next
digit
First
digit
2’s complement Example
1
The 2’s complement of
1011001 is 0100111
The 2’s complement of
0001111 is 1110001
0
0
0
0
0
0
0
1
0
1
1
0
0
1
0
1
0
0
1
1
1
1
0
0
0
0
0
0
0
-
0
0
0
1
1
1
1
1
1
1
0
0
0
1
-
Fast Methods for 2’s Complement
Method 1:
The 2’s complement of binary number is obtained by adding 1 to the
l’s complement value.
Example:
1’s complement of 101100 is 010011 (invert the 0’s and 1’s)
2’s complement of 101100 is 010011 + 1 = 010100
Fast Methods for 2’s
Complement
Method 2:
The 2’s complement can be formed by leaving all least significant 0’s
and the first 1 unchanged, and then replacing l’s by 0’s and 0’s by l’s
in all other higher significant bits.
Example:
The 2’s complement of 1101100 is
0010100
Leave the two low-order 0’s and the first 1 unchanged, and then
replacing 1’s by 0’s and 0’s by 1’s in the four most significant bits.
Examples

Finding the 2’s complement of (01100101)2
 Method 1 – Simply complement each bit and then
add 1 to the result.
(01100101)2
[N] = 2’s complement = 1’s complement (10011010)2
+1
=(10011011)2
 Method 2 – Starting with the least significant bit,
copy all the bits up to and including the first 1 bit
and then complement the remaining bits.
N
[N]
=01100101
=10011011
Binary Coded Decimal
Introduction:
Although binary data is the most efficient
storage scheme; every bit pattern represents a
unique, valid value. However, some applications
may not be desirable to work with binary data.
For instance, the internal components of digital
clocks keep track of the time in binary. The
binary value must be converted to decimal
before it can be displayed.
Binary Coded Decimal
Because a digital clock is preferable to store the
value as a series of decimal digits, where each
digit is separately represented as its binary
equivalent, the most common format used to
represent decimal data is called binary coded
decimal, or BCD.
1) BCD Numeric Format
Every four bits represent one decimal digit.

Use decimal values
from 0 to 9
1) BCD Numeric Format

4-bit values above 9 are not used in BCD.
The unused 4-bit values are:
BCD
1010
1011
Decimal
10
11
1100
1101
1110
12
13
14
1111
15
1) BCD Numeric Format
Multi-digit decimal numbers are stored as
multiple groups of 4 bits per digit.
2) Algorithms for Addition
 1100 is not used in BCD.
2) Algorithms for Addition
Two errors will occurs in a standard
binary adder.
1) The result is not a valid BCD digit.
2) A valid BCD digit, but not the correct
result.
Solution: You need to add 6 to the result
generated by a binary adder.
2) Algorithms for Addition
A simple example of addition in BCD.
0101
5
+ 1001
+ 9
1110
+ 0110
1 0100
1
4
Incorrect BCD digit
Add 6
Correct answer
Binary Coded Decimal
Decimal
Digit
0
1
2
3
4
5
6
7
8
9
BCD
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
Note: 1010, 1011, 1100, 1101, 1110, and 1111 are INVALID CODE!
Let’s crack these…
ex1: dec-to-BCD
(a) 35
(b) 98
(c) 170
(d) 2469
ex2: BCD-to-dec
(a) 10000110
(b) 001101010001
(c) 1001010001110000
BCD Addition
 BCD is a numerical code and can be used in
arithmetic operations. Here is how to add two
BCD numbers:



Add the two BCD numbers, using the rules for
basic binary addition.
If a 4-bit sum is equal to or less than 9, it is a
valid BCD number.
If a 4-bit sum > 9, or if a carry out of the 4-bit
group is generated it is an invalid result. Add 6
(0110) to a 4-bit sum in order to skip the six the
invalid states and return the code to 8421. If a
carry results when 6 is added, simply add the
carry to the next 4-bit group.
BCD Addition
 Try these:
ex: Add the following numbers
(a) 0011+0100
(b) 00100011 + 00010101
(c) 10000110 + 00010011
(d) 010001010000 + 010000010111
(e) 1001 + 0100
(f) 1001 + 1001
(g) 00010110 + 00010101
(h) 01100111 + 01010011
The Gray Code
 The Gray code is unweighted and is not an
arithmetic code.

There are no specific weights assigned to the
bit positions.
 Important: the Gray code exhibits only a
single bit change from one code word to the
next in sequence.

This property is important in many
applications, such as shaft position encoders.
The Gray Code
Decimal
Binary
Gray Code
Decimal
Binary
Gray Code
0
0000
0000
8
1000
1100
1
0001
0001
9
1001
1101
2
0010
0011
10
1010
1111
3
0011
0010
11
1011
1110
4
0100
0110
12
1100
1010
5
0101
0111
13
1101
1011
6
0110
0101
14
1110
1001
7
0111
0100
15
1111
1000
The Gray Code
 Binary-to-Gray code conversion
The MSB in the Gray code is the same as
corresponding MSB in the binary number.
 Going from left to right, add each adjacent pair of
binary code bits to get the next Gray code bit.
Discard carries.
ex: convert 101102 to Gray code

1 + 0 + 1 + 1 + 0
1
1
Gray
1
binary
1
0
The Gray Code
 Gray-to-Binary Conversion
The MSB in the binary code is the same as
the corresponding bit in the Gray code.
 Add each binary code bit generated to the
Gray code bit in the next adjacent position.
Discard carries.
ex: convert the Gray code word 11011 to binary

1
1
+
1
0
+
0
1
+
0
1
Gray
0
Binary
+
1
Alphanumeric Codes
 Represent numbers and alphabetic
characters.

Also represent other characters such as
symbols and various instructions necessary
for conveying information.
 The ASCII is the most common alphanumeric
code.

ASCII = American Standard Code for
Information Interchange
ASCII
 ASCII has 128 characters and symbols
represented by a 7-bit binary code.


(the first 32) – control characters
graphics symbols (can be printed or displayed)
Introduction(Error Checking Code)
 All transmitted signals will contain some rate of errors (>0%) because
noise is always present
 If a communications line experiences too much noise, the signal will be
lost or corrupted

Once an error is detected, a system may perform some
action, or may do nothing but simply let the data in error be
discarded
 Popular error detection methods:



Simple Parity (add a 1 or 0 to the end of each seven bits)
Longitudinal Parity or Longitudinal Redundancy Check (LRC)
Cyclic Redundancy Checksum (CRC), or called Polynomial
checking
Simple
Parity
 Occasionally known as vertical redundancy check
 Add an additional bit to a string of bits:


Even parity
 The 0 or 1 added to the string produces an even
number of 1s (including the parity bit)
Odd parity
 The 0 or 1 added … an odd number of 1s (including the
parity bit)
1 Even parity
0 1 0 1 0 1 0
0 Odd parity
Calculating the Hamming Code
The key to the Hamming Code is the use of extra parity bits to allow the identification of a
single error. Create the code word as follows:
Mark all bit positions that are powers of two as parity bits. (positions 1, 2, 4, 8, 16, 32, 64, etc.)
All other bit positions are for the data to be encoded. (positions 3, 5, 6, 7, 9, 10, 11, 12, 13, 14,
15, 17, etc.)
Each parity bit calculates the parity for some of the bits in the code word. The position of the
parity bit determines the sequence of bits that it alternately checks and skips.
Position 1: check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, etc. (1,3,5,7,9,11,13,15,...)
Position 2: check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, etc. (2,3,6,7,10,11,14,15,...)
Position 4: check 4 bits, skip 4 bits, check 4 bits, skip 4 bits, etc.
(4,5,6,7,12,13,14,15,20,21,22,23,...)
Position 8: check 8 bits, skip 8 bits, check 8 bits, skip 8 bits, etc. (8-15,24-31,40-47,...)
Position 16: check 16 bits, skip 16 bits, check 16 bits, skip 16 bits, etc. (16-31,48-63,80-95,...)
Position 32: check 32 bits, skip 32 bits, check 32 bits, skip 32 bits, etc. (32-63,96-127,160191,...)
etc.
Set a parity bit to 1 if the total number of ones in the positions it checks is odd. Set a parity bit
to 0 if the total number of ones in the positions it checks is even.
Example
Here is an example:

 A byte of data: 10011010





Create the data word, leaving spaces for the parity bits: _ _ 1 _ 0 0 1 _
1010
Calculate the parity for each parity bit (a ? represents the bit position
being set):
Position 1 checks bits 1,3,5,7,9,11:
? _ 1 _ 0 0 1 _ 1 0 1 0. Even parity so set position 1 to a 0: 0 _ 1 _ 0 0
1_1010
Position 2 checks bits 2,3,6,7,10,11:
0 ? 1 _ 0 0 1 _ 1 0 1 0. Odd parity so set position 2 to a 1: 0 1 1 _ 0 0 1
_1010
Position 4 checks bits 4,5,6,7,12:
0 1 1 ? 0 0 1 _ 1 0 1 0. Odd parity so set position 4 to a 1: 0 1 1 1 0 0 1
_1010
Position 8 checks bits 8,9,10,11,12:
0 1 1 1 0 0 1 ? 1 0 1 0. Even parity so set position 8 to a 0: 0 1 1 1 0 0
101010
Code word: 011100101010.
 Finding and fixing a bad bit








The above example created a code word of 011100101010. Suppose
the word that was received was 011100101110 instead. Then the
receiver could calculate which bit was wrong and correct it. The
method is to verify each check bit. Write down all the incorrect parity
bits. Doing so, you will discover that parity bits 2 and 8 are incorrect.
It is not an accident that 2 + 8 = 10, and that bit position 10 is the
location of the bad bit. In general, check each parity bit, and add the
positions that are wrong, this will give you the location of the bad bit.
 Try one yourself
 Test if these code words are correct, assuming they were created using
 an even parity Hamming Code . If one is incorrect, indicate what the
 correct code word should have been. Also, indicate what the original
data was.
 010101100011
 111110001100
 000010001010
A byte of data: 10011010
Create the data word, leaving spaces for the parity bits: _ _ 1 _ 0 0 1 _ 1 0 1 0
Calculate the parity for each parity bit (a ? represents the bit position being set):
Position 1 checks bits 1,3,5,7,9,11:
? _ 1 _ 0 0 1 _ 1 0 1 0. Even parity so set position 1 to a 0: 0 _ 1 _ 0 0 1 _ 1 0 1 0
Position 2 checks bits 2,3,6,7,10,11:
0 ? 1 _ 0 0 1 _ 1 0 1 0. Odd parity so set position 2 to a 1: 0 1 1 _ 0 0 1 _ 1 0 1 0
Position 4 checks bits 4,5,6,7,12:
0 1 1 ? 0 0 1 _ 1 0 1 0. Odd parity so set position 4 to a 1: 0 1 1 1 0 0 1 _ 1 0 1 0
Position 8 checks bits 8,9,10,11,12:
0 1 1 1 0 0 1 ? 1 0 1 0. Even parity so set position 8 to a 0: 0 1 1 1 0 0 1 0 1 0 1 0
Code word: 011100101010.