Binary Codes
Binary Codes
Binary Codes
Book:
1) Moris, M. 2017. digital Design: with an introduction of Verilog HDL, VHDL, and system Verilog, 6 th edition
2) Guy, E.2019 Digital Logic Design. Cambridge university press, UK.
3) tarrate, V. 2022 Digital Design Techniques and Exercises. A practice book for digital logic design, Springer
A set of n-bit string in which different bit strings represent different numbers
or other things is called a code.
A particular combination of n bit values is called a code word.
A code that uses n-bit strings need not contain 2n valid code words.
Binary Codes for Decimal Numbers
It is important to note that this table presents binary codes and not binary
numbers.
A binary number is mathematically defined, while a binary code is just an
assignment of numeric values to bit patterns.
Binary Codes for Decimal Numbers
Each such assignment in table 2-9 does have some particular property associated
with it that makes it a reasonable method of assignment.
For example, a BCD number is just a natural binary encoding of the decimal
digits from 0 to 9 on four bits.
Therefore a string of bits is grouped into groups of four bits, and interpreted as a
string of decimal
Binary-Coded Decimal (BCD)
A BCD number is just a natural binary encoding of the decimal digits from 0 to 9
on four bits.
59 in BCD (0 ~ 99) because there are unused code words
87 in normal unsigned binary number (0 ~ 255)
Binary-Coded Decimal (BCD)
This code has the advantage that it is self-complementing, that is, the code word
for the 9s’ complement of any digit may be obtained by complementing the
individual bits of the digit’s code word.
0010 = 2
9s’complement of 2 can be obtained by complementing individual bits1101 =
(2+0+4+1 ) = 7
Excess – 3 Code
This code is is the sparsest encoding of decimal digits, using 10 out of 1024
possible 10-bit code words.
10000 00000 = 0
01000 00000 = 1
00100 00000 = 2
The redundant bits gave this code the error-detecting property.
Binomial Coefficients
The number of different ways to choose m items from a set of n items is given by
a binomial coefficient, denoted by whose value is n!/(m!*(n-m)!)
for a 4-bit decimal code, there are different ways to choose 10 out of 16 4-bit
code words, and 10! ways to assign each different choice to the 10 digits. So there
are (16!/(10!*(16-10)!))*10! Or 29059430400 different 4-bit decimal codes.
Gray Code
Gray code is a code where only one bit changes at a time while traversing from 0
to any decimal number in sequence.
This is a useful property when converting analog values into digital values, since
it eliminates the problem of misinterpreting asynchronous changes to bits
between valid values.
Gray Code
What value will the encoder produce if the disk is positioned right on the theoretical
boundary?
Gray Code
Gray code is defined from the binary code using the following rules: The bits of
an n-bit binary or Gray-code code-word are numbered from right to left, from 0 to
n-1.
Bit i of a Gray-code code-word is 0 if bits i and i+1 of the corresponding binary
code word are the same, else bit i is 1. (When i+1=n, bit n of the binary code
word is considered to be 0.)
Character Codes
Many applications of digital computers require the handling of data not only of
numbers, but also of letters.
The most commonly used character code is ASCII (the American Standard Code
for Information Interchange).ASCII represents each character with a 7-bit string,
yielding a total of 128 characters.
The code contains the uppercase and lower case alphabet, numeral, punctuation,
and various nonprinting control characters.
Other Codes
An error in a digital system is the corruption of data from its correct value to
some other value.i.e.,
a change of some bits from 0 to 1 or vice versa.
During the processing or transmission of digital data a noise may change some
bits from 0 to 1 or vice versa.
A short duration noise can affect only a single bit causes a single-bit error.
A long duration noise can affect two or more bits causes a multi-bit error.
Codes for detecting and correcting errors
The receiver processes the incoming data using the same algorithm and then
compares it’s CRC with the one transmitted. If they are the same, the data must be
correct.CRC-16 detects 99.99% errors; that is 1 in 10,000 errors goes
undetected.CRC-32 is extremely proficient in detecting errors; approximately 1 in
errors go undetected.
Checksum
A checksum is calculated by adding up the decimal value of each character in the
message, dividing the sum by 255 and using the remainder as the checksum to be
transmitted with the message.
Digital Encoding of Digital Data
Unipolar (the voltage always positive or negative, 0v for 0 and 5v for 1)Bipolar (fewer
errors than unipolar signaling as changing the polarity of a current/voltage is more difficult
than changing its magnitude, -5v for 0, +5v for 1)
RZ (return to zero)
NRZ (non return to zero)
NRZ-L (NRZ, level)
NRZ-I (NRZ, invert on ones)
Digital Encoding of Digital Data
Biphase (all of the biphase techniques require at least one transition per bit time
and may have as many as two transitions.
Manchester (used in Ethernet LANs) - The midbit transition serves as a clocking
mechanism and also as data.
0 - a high-to-low represents a 0, and
1 - A low-to-high represents a 1.
Differential Manchester (used in Token-ring LANs) - The midbit transition is
used only to provide clocking.
0 - A transition at the beginning of the bit period represents 0, and
1 - an absence of a transition at the beginning of the bit period represents 1.
Serial Lines Codes