Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Haming

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Page -1

Green University of Bangladesh


Dhaka-1207

Data Communication Lab (CSE 308)

A group project submitted on hamming code generation and


error correction.

Submitted by: Submitted to:


Md. Mir Sultan 191015191 Mozdaher Abdul Quader
Mafizar Rahman 191015193 Lecturer
Md. Suzan Miah 191015056 Department of CSE
MD. Rubel Sonar 191015170

January 2021
Page -2

TABLE OF CONTENTS
STRING
STRING
ASCII
HAMMING CODE
ABSTRACT
REDUNDANT
Parity bits .............................................................................................
Determining the position of redundant bits
Determining the Parity bits ...................................................................
ERROR DETECTION AND CORRECTION
CODE IMPLEMENTATION IN JAVA
STRING PART:
STRING PART:
CONCLUSION

String
Page -3

What is string in programming:


In computer programming, a string is traditionally a sequence of
characters, either as a literal constant or as some kind of
variable. The latter may allow its elements to be mutated and the
length changed, or it may be fixed (after creation). A string is
generally considered as a data type and is often implemented as
an array data structure of bytes (or words) that stores a
sequence of elements, typically characters, using some
character encoding. String may also denote more general arrays
or other sequence (or list) data types and structures.

In formal languages, which are used in mathematical logic and


theoretical computer science, a string is a finite sequence of
symbols that are chosen from a set called an alphabet.

ASCII:
ASCII abbreviated from American Standard Code for Information
Interchange, is a character encoding standard for electronic
communication. ASCII codes represent text in computers,
telecommunications equipment, and other devices. Most modern
character-encoding schemes are based on ASCII, although they
support many additional characters.

The Internet Assigned Numbers Authority (IANA) prefers the


name US-ASCII for this character encoding.
Page -4
Page -5

Hamming Code

Abstract
The Hamming code is a well-known error correction code and can
correct a single error in an input vector of size n bits by adding
logn parity checks. A new parallel implementation of the code is
presented, using a hierarchical structure of n processors in logn
layers. All the processors perform similar simple tasks, and need
only a few bytes of internal memory.

Hamming code is a set of error-correction codes that can be used


to detect and correct the errors that can occur when the data is
moved or stored from the sender to the receiver. It is technique
developed by R.W. Hamming for error correction.

Redundant bits
Redundant bits are extra binary bits that are generated and added
to the information-carrying bits of data transfer to ensure that no
bits were lost during the data transfer.
The number of redundant bits can be calculated using the
following formula:
2^r ≥ m + r + 1
where, r = redundant bit, m = data bit
Suppose the number of data bits is 7, then the number of
redundant bits can be calculated using:
= 2^4 ≥ 7 + 4 + 1
Thus, the number of redundant bits= 4
Parity bits

A parity bit is a bit appended to a data of binary bits to ensure that


the total number of 1’s in the data is even or odd. Parity bits are
used for error detection. There are two types of parity bits:
Page -6

1. Even parity bit:

In the case of even parity, for a given set of bits, the number of
1’s are counted. If that count is odd, the parity bit value is set to
1, making the total count of occurrences of 1’s an even
number. If the total number of 1’s in a given set of bits is
already even, the parity bit’s value is 0.
2. Odd Parity bit:

In the case of odd parity, for a given set of bits, the number of
1’s are counted. If that count is even, the parity bit value is set
to 1, making the total count of occurrences of 1’s an odd
number. If the total number of 1’s in a given set of bits is
already odd, the parity bit’s value is 0.

Determining the position of redundant bits


These redundancy bits are placed at the positions which
correspond to the power of 2.
As in the above example:
1. The number of data bits = 7
2. The number of redundant bits = 4
3. The total number of bits = 11
4. The redundant bits are placed at positions corresponding to
power of 2- 1, 2, 4, and 8
Page -7

Suppose the data to be transmitted is 1011001, the bits will be


placed as follows:

Determining the Parity bits

1. R1 bit is calculated using parity check at all the bits positions


whose binary representation includes a 1 in the least significant
position.
R1: bits 1, 3, 5, 7, 9, 11

To find the redundant bit R1, we check for even parity. Since
the total number of 1’s in all the bit positions corresponding to
R1 is an even number the value of R1 (parity bit’s value) = 0

2. R2 bit is calculated using parity check at all the bits positions


whose binary representation includes a 1 in the second
position from the least significant bit.
R2: bits 2,3,6,7,10,11
Page -8

To find the redundant bit R2, we check for even parity. Since
the total number of 1’s in all the bit positions corresponding to
R2 is odd the value of R2(parity bit’s value) =1

3. R4 bit is calculated using parity check at all the bits positions


whose binary representation includes a 1 in the third position
from the least significant bit.
R4: bits 4, 5, 6, 7

To find the redundant bit R4, we check for even parity. Since
the total number of 1’s in all the bit positions corresponding to
R4 is odd the value of R4(parity bit’s value) = 1
Page -9

4. R8 bit is calculated using parity check at all the bits positions


whose binary representation includes a 1 in the fourth position
from the least significant bit.
R8: bit 8,9,10,11

To find the redundant bit R8, we check for even parity. Since
the total number of 1’s in all the bit positions corresponding to
R8 is an even number the value of R8(parity bit’s value) =0.
Thus, the data transferred is:
Page -10

Error detection and correction

Suppose in the above example the 6th bit is changed from 0 to 1


during data transmission, then it gives new parity values in the
binary number:


The bits give the binary number as 0110 whose decimal
representation is 6. Thus, the bit 6 contains an error. To correct
the error, the 6th bit is changed from 1 to 0.
Page -11

Code Implementation in Java:

String part:
Given a string of character the task is to convert each character
of a string into the equivalent binary number.
For example:

"Hello World!" should turn into 


1001000 1100101 1101100 1101100 1101111 100000 1010111
1101111 1110010 1101100 1100100 100001.
The idea is to first calculate the length of the string as n and then
run a loop n times. In each iteration store ASCII value of
character in variable Val and then convert it into binary number
and store result in array finally print the array in reverse order.
Examples:

Input: GFG
Output: 1000111 1000110 1000111

Input: geeks
Output: 1100111 1100101 1100101 1101011 1110011

Hamming code part:


Hamming code is a set of error-correction codes that can be used
to detect and correct the errors that can occur when the data is
moved or stored from the sender to the receiver.

Examples:
Page -12

Input:
message bit = 0101
r1 r2 m1 r4 m2 m3 m4
0 1 0 1
Output:
Generated codeword :
r1 r2 m1 r4 m2 m3 m4
0 1 0 0 1 0 1

Explanation:
Initially r1, r2, r4 is set to '0'.
r1 = xor of all bits position
which has '1' in its 0th-bit position
r2 = xor of all bits
which has '1' in its 1st-bit position
r3 = xor of all bits
which has '1' in its 2nd-bit position

Output:
Generated hamming code
r1 = 0
r2 = 1
r4 = 0
0100101
Page -13

Conclusion:
So in this article, we have seen how to convert a String to binary
bit data and the hamming code technique works for error
detection and correction in a data packet transmitted over a
network. The Hamming code is a well-known error-correcting
code.

You might also like