Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

xx!

M O D U L E 1 0 :

CODING IN
COMPUTER
GROUP 1 POWERPOINT PRESENTATION
BINARY
CODES
This discusses Binary Coded Decimal and its decimal digit
representation and convert numbers from base to another and its BCD.
Binary Codes

• Digital computers use the binary numbers 0 and 1. Input is done in decimals
and converted in binary for internal processing.

Illustration:
1001 0111 0101 0001 0001
975 11

{
{

{
{

{
8 +1 4+2+1 4+1 1 1

1 0111 0101 0001 0010


.75 12

{
{
{
{
{

1 7 5 1 2

75 0111 0101 13 0001 0011


{
{

{
{
7 5
1 3
A commonly used code is the Binary Coded Decimal (BCD) code which corresponds to the first
10 binary representation of the decimal digits 0-9. Since 4 bits may have up to42 binary
combinations, a total 6 combinations will be unused. The position weights of the BCD
are 8, 4, 2, 1.

Decimal BCD In the 16 binary combinations, the 6 combinations


Digit 8-4-2-1 unused are as follows

0 0000 0001 0011


0001 0000
1 0001
10 13

{
{
{
{
2 0010 1 0
1 3

3 0011 0001 0100


0001 0001 14
4 0100 11

{
{
{
{
5 0101 1 1
1 4

6 0110 0001 0010 15 0001 0110


7 0111 12

{
{
{
{
1 5
8 1000 1 2

9 1001
Example:
a. We perform the following division:
14 divided by 2 is 7 rem. 0
7 divided by 2 is 3 rem. 1
3 divided by 2 is 1 rem. 1
1 divided by 2 is 0 rem. 1

Note, to be able to detect errors at the receiver ends, the sender sends an extra bit called
parity bit. A parity bit is an extra bit included with n-bit binary message to make the total
of 1’s message which may be either odd or even.
CHARACTERS IN
COMPUTER
Characters in Computer

• In computer and machine-based telecommunications terminology, a character is a


unit of information that roughly corresponds to a grapheme, grapheme-like unit, or
symbol, such as in an alphabet or syllabary in the written form of a natural language.

Printable characters include the upper and lower cases letters (2 x 26), the 10
numerals (0-9), & 12 special characters (e.g. @, ‘, ~, !, #, $, %, ^, &, *, (, ), _, -, =,
+, [, ], {, }, ;, :, “, \, |, <, >, /, ?, ‘.)

Bases refers to a system of grouping numbers.

The base 10 has 10 symbols, namely 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. In base 3, there


are only 3 symbols, namely 0, 1, and 2.
This table shows the other numbering system.
This table gives the comparison of 3 bases, (base 10, base 3, and base
12) in the fifteen counting numbers.
COMPUTER
ARITHMETIC
Computer Arithmetic

• Is a branch of computer engineering that deals with methods of


representing integers and real values in digital systems through efficient
manipulation.

• The hardware are types of adders, sub tractors, multipliers, dividers,


roots, and circuit techniques for function evaluation.

• The software side of computer arithmetic includes complexity, error


characteristic, stability, and algorithms.
Example:
a. Convert 21 to radix 5.
b. 21 in 8-bit signed-magnitude binary code 00011011
c. 127 in 2-digit decimal code with BCD digits 001 0010 0111
d. -21 in 2-digit decimal code with BCD digits 1 0010 0111

0000
1111 0 0001
-1 1

0010
1110 2
-2

This figure shows the encoding of 1101 -3 3


0011

positive and negative integers in


the 4-bit 2’s-complement format. 0100
-4 4
1100

-5 5 0101
1011

-6
6
0110
1010
-7 7
-8 0111
1001 1000
Schematic Diagram of 4-bit2’s-compliment code for
integers in -8 up to 7 :
Fixed-Point Numbers
A fixed-point number consists of a whole and decimal part where the two parts are
separated by a radix point.

Illustrates the fixed-pointed numbers:


-1 -3
10.0112 = (1 x 21 ) + (0 x 02 ) + (0 x 2 ) + (1 x-2 2 ) + (1 x 2 ) = 2.375
-1 -3
10.1112 = (1 x 21 ) + (0 x 20 ) + (0 x 2 ) + (1 x-2 2 ) + (1 x 2 ) = 2.875
-.125 0
.125
-.25
.25

-.375
.375

-.75

.5

-.625
.625
-.75
.75
-.875
-1 .875
Schematic Diagram of 4-bit2’s-compliment code for
integers in -8 up to 7 :
CONVERTING
DECIMALS
TO RADIX 2
Converting Decimals to Radix 2

• To perform radix conversion using arithmetic with the given radix of 2, we


repeatedly multiply the fractional part by 2, noting and removing the integer part
in each step.

Example:
a. Convert .0625 to radix 2

Solution. 625 x 2 = .125 with an integer part 0


.625 x 2 = .125 with an integer part 0
.125 x 2 = .25 with an integer part 0
.25 x 2 = 5 with an integer part 0
.5 x 2 = 0 with an integer part 1
The solution is obtained from top to bottom of the integral parts, that is, .625 = 00012
-2 -3
Check. (0 x 2-1 ) + (0 x 2 ) + (0 x 2 ) + ( 1 x 2-4 ) = .0625
DETECTING AND
CORRECTING ERROR
Detecting and Correcting Error

• Error detection is the detection of errors caused by noise or other impairments during
transmission from the transmitter to the receiver. Error correction is the detection of
errors and reconstruction of the original, error-free data.

• Coding is also known as source coding and channel coding.


The goal of the coding theory is to detect error transmitted and in
turn correct the error.

Message
Source Decoder
Noise Channel
Source Encoder
Receiver
If the receiver does not get the correct word, we use the method or scheme of
adding more bits. The aim of this method is called a scheme to detect error and correct
the error it in the channel.

Addition of 1 bit gives detecting the error but not correcting it.

00 000
10 101
Use 3 bits in a message of 2 bits.
01 011
11 110

Example.
1. The message 00 is encoded as 000 after the source.
2. If one error is detected, the sent message is one of the three words
100, 010, 001
3. The error is detected but none of the three words 100, 010, 001 is among the
messages 101, 011, or 110
Use more bits
We design the channel coding scheme by using more bits as follows:
If we use more bits such as 6 bits, the error is corrected. Suppose we have decoded words
of two bits in 6 bits as follows:

00 000000
10 101111
01 010110
11 111100

a) In the codeword 00, we decode it as “000000”


b) Due to interference over a noisy channel, suppose we have 1-error detected.
The codeword may either be one of the following:
000001 000010 000100 00100 001000 010000 100000
00
(000001, 001111) = 3 errors
Coded
(000001, 010110) = 4 errors 000000
Noise
000001
least error
000000
(000001, 111100) = 5 errors
00
HAMMING DISTANCE
Hamming Distance

• Is a metric for comparing two binary data strings. While comparing two binary
strings of equal length, Hamming distance is the number of bit positions in which
the two bits are different.

Illustration: Let m = 01 and n = 10, then d(m, n) = 2


Let m = 01 and n = 11, then d(m, n) = 1

Example. A = {0, 1, 2, 3} and let x = 123, z = 132


Find d(x, y), d(x, z), and d(y, z)
Solution. D(x, y) = 2, d(x, z) = 2, and d(y, z) = 3
Let a code S containing at least two words, and then the minimum distance of S,
denoted by d(S), is
d(S) = min {d(m, n) / m, n S, m = m}
THANKS! FOR LISTENING!

CREDITS: This presentation template was created by Slidesgo, including icons by Flaticon, and infographics & images by Freepik.
Please keep this slide for attribution.

You might also like