Вы находитесь на странице: 1из 27

S.

No Name of Experiment Date of Remarks


Experiment
1. Establishment and configuration of LAN.
2. Color coding standards of CAT-5, CAT-
6, CAT-7 and RJ-45.
3. Study of WAN.
4. Case study of Stop and Wait protocol.
5. Study of Sliding Window Protocol.
6. Study of basic networking commands
like ping,ipconfig.,etc.
7. Case study of various routing strategies.
8. Case study of various network
topologies.
9. Implementation of VRC.
10. Implementation of LRC.
11. Implementation of CRC.
12. Implementation of Hamming Code.
13. Implementation of Dijkstra’s routing
algorithm.

INDEX
EXPERIMENT NO. 1

ESTABLISHMENT AND CONFIGURATION OF LAN.

A local area network (LAN) is a computer network that connects computers and devices in a
limited geographical area such as home, school, computer laboratory or office building. The
defining characteristics of LANs, in contrast to wide area networks (WANs), include their
usually higher data-transfer rates, smaller geographic area, and lack of a need for leased
telecommunication lines
Fig 1.1

ESTABLISHING LAN

Hardware Required

To create an RJ45 local area network in Windows, we need:

i. Several computers running Windows (computers running two different versions of


Windows can be part of the same network).
Fig 1.2

ii. Ethernet cards on a PCI or ISA port (with an RJ45 plug) or built into the motherboard.
When applicable, make sure the diodes

        Fig 1.3

On the back of the network card light up when the computer is on and that a cable is plugged
in! There are also network adapters for USB ports, particularly in the case of wireless
network adapters;

iii. RJ45 cables in the case of wired networks.

       

iv. A hub, a device you can connect the RJ45 cables from the network's various computers to,
or a switch,

The structure of such a network looks like this:

                                                                     Fig 1.4

ARCHITECTURE TO AVOID:-
Incorrect RJ45 network

Fig 1.5

Configuration of LAN:-

    1. Bandwidth:-

         On LAN technologies, the usual bandwidth is 10Mbps, 100Mbps, 1000Mbps and
starting now in some cases, 10000Mbps.

     

Usual LAN bandwidth


Description Bandwidth
User workstation 10 or 100Mbps
IP Phone 100Mbps
Server 10, 100 or 1000Mpbs
Connection to WAN router 10, 100 or 1000Mpbs
Connection between switches 1000Mbps or an aggregation of n*1000Mbps
Now starting with 10000Mpbs

Table 1.1

2. Amount of ports:-

       i. When designing or upgrading a LAN infrastructure, it is necessary to be prepared for


growing.
         ii. Experience has shown that a 30% free port margin is good practice (1.3*used
connections).

      iii. As an example, if a LAN needs 16 connections, it is better to install a 24 port switch.

References:-

 .http://duxcw.com/digest/Howto/network/cable/cable5.htm
 http://nullmodem.com/RJ-45.htm
 http://en.wikipedia.org/wiki/Registered_jack -

EXPERIMENT No. 2

COLOR CODING STANDARDS OF CAT-5, CAT-6, CAT-7 AND


CRIMPING IN RJ-45

Cat-5:-

Category 5 cable is a twisted pair high signal integrity cable type often referred to
as Cat5 or Cat-5. Most Category-5 cables are unshielded, relying on the twisted pair design
for noise rejection. Category 5 has been superseded by the Category 5 specification. This type
of cable is used in structured cabling for computer networks such as Ethernet and ATM, and
is also used to carry many other signals such as telephony and video.

        

                        

Fig 2.1

Cat-6:-

Category 6 cable, commonly referred to as Cat.-6, is a cable standard for Gigabit


Ethernet and other network protocols that are backward compatible with the Category
5/5e and Category3  cable standards. Compared with Cat.-5 and Cat.-5e, Cat.-6 features more
stringent specifications for crosstalk and system noise. The cable standard provides
performance of up to 250 MHz and is suitable for 10BASE-T, 100BASE-TX (Fast
Ethernet), 1000BASE-T/1000BASE-TX (Gigabit Ethernet) and 10GBASE-T (10-Gigabit
Ethernet). Category 6 cable has a reduced maximum length when used for 10GBASE-T;
Category 6a cable, or Augmented Category 6, is characterized to 500 MHz and has
improved alien crosstalk characteristics, allowing 10GBASE-T to be run for the same
distance as previous protocols. Category 6 cable can be identified by the printing on the side
of the cable sheath.

Fig 2.2

CRIMPING IN RJ45:-

1. RJ45:-    

     RJ45 connectors are commonly used with Cat5 cable to connect computers to
networks. The connection can be to an Ethernet network, or to an Internet connectivity
device such as a router, cable modem, or DSL modem.Cat5 cable contains a set of color-
coded cable wire pairs. When the cable is connected to an RJ45 connector, the color-
coded wires must be set in a particular order that varies with the intended usage. We use
a crimping tool to connect or crimp the RJ45 connector and the Cat5 cable.

     

2. Things Required:-

            i. CAT5 cable

            ii. RJ 45 connectors

            iii. Crimping tool

3. Procedure:-

         a) Cut the CAT5 cable to the desired length. Strip 2 inches of jacket off one
end of the cable, exposing the color-coded wire pairs within.

          b)  Reorganize the color-coded wires into the pattern required for your
particular use.
          c) Flatten and align the color-coded wires, then cut them in a straight line at a
length of between a 1/2 inch and 3/4 inch.

           d) Place an RJ 45 connector on the end of the cable with the prong on the
underside.

                                Fig 2.3

e) Push the connector onto the wires until the copper ends of the wires are visible
through the end of the connector.

f) Place the RJ 45 connector in the crimping tool.

                g) Crimp the connector by squeezing the crimping tool to force the


contacts through the insulation on the wires.

Fig 2.4-Crimping Tool

References:-

 http://duxcw.com/digest/Howto/network/cable/cable5.htm
 http://nullmodem.com/RJ-45.htm
 http://en.wikipedia.org/wiki/Registered_jack -
 www.pjtool.com.
EXPERIMENT NO. 4
CASE STUDY OF STOP AND WAIT PROTOCOL
Design and Implementation

Assumption: Error free communication channel

            The sender in this protocol simply retrieves a packet from the network layer, copies it
into a frame, and then transmits it.  After transmission, the sender busy waits until an
acknowledgement is received from the receiver, then the loop starts over again.

                        

The receiver simply busy waits until a frame is received.  Once a frame is received it
passes the data packet to the network layer and sends an acknowledgement for the frame it
just received.  It then loops back to busy waiting and the process continues until the End of
File is reached.

        In this protocol, there can only be one outstanding frame at a time so no sequence
numbers are required and the acknowledgement the receiver sends back to the sender is
nothing more than an empty frame, as there is no other possibility then acknowledging the
only frame sent.  Another frame will not be sent until this acknowledgement is received.

Performance

The Stop and Wait protocol was very easy to implement and runs very quickly and
efficiently. It solves the problem of congestion, as only one frame is outstanding at any time,
frames cannot be lost due to congestion and the receiver  will not be swamped by the sender.

Point of failure

        The problem with it is that it assumes an error free communication channel and in the
real world, such a channel does not exist.   It is easy to see that if a frame or an
acknowledgement gets lost or damaged, a deadlock situation will occur where neither the
sender or receiver can advance, and they will be thrown into infinite loops.

                                                                           

Fig 4.1

                                             Fig 4.2

REFERENCES:

http://en.wikipedia.org/wiki/Stop-and-wait_ARQ

http://www.javiervalcarce.eu/wiki/The_Stop-And-Wait_ARQ_Protocol

EXPERIMENT NO.3
CASE STUDY OF WAN

WAN:

A wide area network (WAN) is a computer network that covers a broad area (i.e., any
network whose communications links cross metropolitan, regional, or national boundaries ).
This is in contrast with personal area networks (PANs), local area networks (LANs), campus
area networks(CANs), or metropolitan area networks (MANs) which are usually limited to a
room, building, campus or specific metropolitan area (e.g., a city) respectively.

WAN  DESIGN OPTIONS:

The WAN design options are:

 Through Internet service providers, they provide connections from an organization's


LAN to the Internet.
 WANs are often built using leased lines. At each end of the leased line, a router
connects to the LAN on one side and a hub within the WAN on the other.
 WANs can also be built using  circuit switching or packet switching methods.

Option Description Advantages Disadvantages Bandwidth Sample


range protocols
used
Leased line Point-to-Point Most secure Expensive PPP, HDLC,
connection SDLC, HNAS
between two
computers or
Local Area
Networks
(LANs)
Circuit A dedicated Less Call Setup Call Setup PPP, ISDN
switching circuit path is Expensive
created
between end
points. Best
example is
dialup
connections
Packet Devices Shared media X.25 Frame-
switching transport across link Relay
packets via a
shared single
point-to-point
or point-to-
multipoint link
across a carrier
internetwork.
Cell relay Similar to Best for Overhead can be ATM
packet simultaneous considerable
switching, but use of voice
uses fixed and data
length cells
instead of
variable length
packets

Table 3.1

ADVANTAGES OF WAN:

1. Covers a large geographical area so long distance businesses can connect on the one
network.
2. Shares software and resources with connecting workstations.
3. Messages can be sent very quickly to anyone else on the network. These messages
can have pictures, sounds, or data included with them (called attachments).
4. Share information/files over a larger area.

      

                                                      Fig 3.1

References:

http://www.cisco.com/en/US/docs/internetworking/technology/handbook/Intro-to-WAN.html

http://www.compnetworking.about.com/cs/lanvlanwan/g/bldef_wan.htm
EXPERIMENT NO. 5

CASE STUDY OF SLIDING WINDOW PROTOCOL

Sliding window is a flow control technique which belongs to the Data Link layer of the OSI
model. It solves the problem of missing frames during data transmission between two upper
layers, so that they can send and receive frames in order.

Two Acknowledgement Schemes

In sliding window mechanism, receiver sends out acknowledgement to sender to notify of


receiving or missing of frames. There are two acknowledgement schemes.

ACK scheme is used on a noisy link, in which receiver sends an ACK for every frame
received (note that when the receiver sends an acknowledge for frame s, this is understood to
mean that all frames up to and including s have been received).

NAK (negative acknowledgement) is used on a reliable link on which message loss is not
frequent. In this scheme receiver only sends an ACK for a lost frame.

Sliding Window

With a stop-and-wait protocol, the sender waits for an acknowledgment after transmitting
every frame. As a result, there is at most a single outstanding frame on the channel at any
given time, which may be far less than the channel's capacity. For maximum throughput, the
amount of data in transit at any given time should be (channel bandwidth) * (channel delay).

The key feature of the sliding-window protocol is that it permits pipelined communication to
better utilize the channel capacity. The sender can send a maximum N frames without
acknowledgement. N is called the window size of the sliding window. The sliding window
maps to the frames in sender’s buffer that are to be sent, or have been sent and now are just
waiting for acknowledgement. 

The sender assigns a sequence number to each frame. At any time, the sender maintains the
list of sequence numbers corresponding to frames it is permitted to send. For example, TCP
connection establishment involves the sender and receiver exchanging their start squence
numbers in the SYN/ACK packets

Since frames currently within the sender's window may ultimately be lost or damaged in
transit, the sender must keep all these frames in its memory for possible retransmission. Thus,
the sender must have a buffer of at least the size of the sliding window.

The sender records the time at which each packet is sent. If the sender does not receive an
acknowledgment for a frame after timeout, it retransmits the this frame.
For a receiver using selective repeat, the sliding window is the group of frames that its
receiving buffer maps to. A receiver using Go-back-N does not have a buffer and thus does
not have a concept of window.

Sophisticated protocols can dynamically adapt the window size, trying to find a size suitable
for both sender and receiver. Receiver can indicate the new desired window size in the
acknowledgement.

All following examples uses a window size of 8.

Receiver Logic in Go-back-N

In Go-back-N, receiver does not need a buffer.

When it first receives frame 0, it pass it on to higher protocol and returns ACK0 to sender.
Then it receives 1, 2, 3, 4 and does the same thing. After it receives 4, it receives 6, and it
knows that frame 5 is missing. So it will discard frame 6 and all later frames (7, 0, 1, ..), until
it receives frame 5.

Receiver Logic in Selective Repeat

In Selective Repeat, receiver has a buffer of the window size to cope with out-of-order
frames. It always tries to pass on as many frames as possible in the buffer to higher protocol
layer.

Suppose the receiver has just passed on frame 4, and the buffer is now empty. Now frame 5
arrives. It will pass it on straight-away and returns ACK5 to sender. Then comes frame 6, 7,
0, 1, 2, 3 and it does the same thing. The buffer is kept empty.

After frame 3 arrives, there comes frame 5, and the receiver knows that frame 4 is missing. It
will not directly pass frame 5 on, nor will it discard it. Instead it puts frame 5 in the second
place in the buffer, and returns ACK5. When later frames arrives, the receiver puts them
sequentially in the buffer and returns ACK for each of them, until the buffer is full. Then it
will discard all following frames and do not acknowledge them. All through this process it
will not pass on any frame until the first missing one arrives.

This way the sender needs to send only the missing frame, and the receiver can still pass on
frames in order.

Sender Logic

After sender sends out its full window, it waits for ACK. If it has received ACK for all
frames up to frame n, it will move its window to contain following frames, so that the first
frame in the window is frame (n + 1). Then it sends out all unsent frames in this window and
waits for new ACK.

Suppose  sender has sent out its full window 0 ~ 7 and is now waiting for ACK, and frame 3
is lost. It will first receive ACK 0, 1, 2, and it moves its window to 3, 4, 5, 6, 7, 0, 1, 2 and
sends unsent frames 0, 1, 2, and continue to wait. Suppose 0, 1, 2 is received by the receiver.
If it is Go-back-N, it will not receive any more ACK after ACK 0, 1, 2. After time out, it
knows that frame 3 and all following frames are lost. So it will resend all frames in the
window: 3, 4, 5, 6, 7, 0, 1, 2.

If it is Selective Repeat, it will receive ACK 4, 5, 6, 7, 0, 1, 2 after receiving ACK 2. It will


not move window because the first frame in the window (frame 3) hasn’t been
acknowledged. It will just wait until time out. Then it knows that frame 3 is missing, so it will
resend frame 3 only, and continue to wait, until ACK 3 is received or timeout again. Then the
content of the whole window has been acknowledged. It will move to next window and send
the 8 new frames.

Overview

Selective repeat ARQ is seldom used because of its requirement on receiver’s buffer.

Performance

The Go Back N protocol is fairly tricky to implement. If the window size matches the range
of sequence numbers the protocol can break and implementation is extremely difficult. By
using the range of sequence numbers greater than the window size, the receiver and the
sender can be kept in synchronization even when frames and acknowledgements are lost at
high rate. The Protocol easily handles congestion errors, bad frames and lost frames. Most
difficult part was trying to find the optimum timeout value that provided efficient
transmission for all error rates. Smaller timeout value seemed better on higher error rates but
to optimize at lower error rates a slightly higher value of timeout was selected.

The Selective Repeat protocol was difficult to implement. The sequence numbers need to be
greater than the window size so that no overlap can occur in the window. This allows receiver
and sender to be kept in synchronization even when frames and acknowledgements are lost at
a very high rate. The buffering and acknowledgements allow this protocol to easily handle
congestion, bad frames and lost frames. It was found that a much higher timeout value is
needed than in Go Back N  in order to reduce the number of frames sent. A lower timeout
value results in too many frames timing out and being retransmitted unnecessarily, since the
receiver maintains a buffer of frames and can send a nak for exactly the frame sequence
number it needs. We have chosen 25 as a timeout value, and kept the from_physical_layer
parameter to 100,000 because these two values worked the best for a wide range of error
rates.
                 

Fig 5.1

REFERENCES:

http://en.wikipedia.org/wiki/Selective_Repeat_ARQ

www.javvin.com/networkingterms/SelectiveRepeatARQ.htm
EXPERIMENT NO 10

IMPLEMENTATION OF LONGITUDINAL REDUNDANCY


CHECK(LRC)

WHAT IS LRC:

 In Longitudinal redundancy check (LRC),a block of bits is organized in a table(rows  

 and columns).

 Then calculate the parity bit for each column and create a new row of 8 bits, which

 are the parity bits for the whole block.

 First parity bit in the fifth row is calculated based on all first bits,and so on.
 Then attach the 8 parity bits to the original data and send them to the receiver.

Original data

11100111    11011101   00111001    10101001

                                        

                                        1 1 1 0 0 1 1 1

                                        1 1 0 1 1 1 0 1

                                        0 0 1 1 1 0 0 1

                                        1 0 1 0 1 0 0 1

                                        -----------------

                                        1 0 1 0 1 0 1 0 ßLRC

 11100111    11011101   00111001    10101001    10101010

The above is the original data plus LRC

CODE:

#include<stdio.h>

#include<conio.h>

void main()

{
char a[12],b[4],c[4],d[4];

int LRC[4];

int i;

clrscr();

printf("enter a 12 bit binary string:\n");

fflush(stdin);

scanf("%s",a);

printf("the string segments are:\n");

for(i=0;i<4;i++)

b[i]=a[i];

c[i]=a[i+4];

d[i]=a[i+8];

for(i=0;i<4;i++)

printf("%c",b[i]);

printf("\n");

for(i=0;i<4;i++)

printf("%c",c[i])\\

printf("\n");

for(i=0;i<4;i++)
{

printf("%c",d[i]);

for(i=0;i<4;i++)

LRC[i]=(b[i]-48)^(c[i]-48)^(d[i]-48);

printf("\nyour LRC code is:\n");

for(i=0;i<4;i++)

printf("%d",LRC[i]);

getch();

OUTPUT

enter a 12 bit binary string:

101011001110

the string segments are:

1010

1100

1110

your LRC code is:

1000

References:-

 www.wikipedia.com
 www.google.com
EXPERIMENT No.9

IMPLEMENTATION OF VERTICAL REDUNDANCY CHECK

       In telecommunications, vertical redundancy check(VRC) is a redundancy check for


synchronized parallel bit streams that is applied once per bit time, across the bit streams. This
requires additional parallel channels for the check bit or bits.

Parity check

Parity check (sometimes called VRC, for Vertical Redundancy Check or Vertical
Redundancy Checking) is one of the simplest checking mechanisms. It involves adding an
additional bit (called a parity bit) to a certain number of bits of data called a code word
(generally 7 bits, so as to form a byte when combined with the parity bit) whose value (0 or
1) is such that the total number of 1 bits are even. To be more straightforward, 1 if the
number of bits in the code word is odd, 0 otherwise.

Fig 11.1

        

CODE:

#include<stdio.h>

#include<conio.h>

void main()

{
char arr[8];

int i,count=0,vrc;

clrscr();

printf("enter a binary string:");

scanf("%s",arr);

for(i=0;i<8;i++)

        {

        if(arr[i]=='1')

        count++;

        }

        if(count%2!=0)

        vrc=1;

        else

        vrc=0;

        printf("\nvrc  of given code is :%d",vrc);

        printf("\nour code to transmitt is:");

        for(i=0;i<5;i++)

        printf("%c",arr[i]);

        printf("%d",vrc);

        getch();

 }

                       

OUTPUT

enter a binary string:10111101

vrc  of given code is :0


our code to transmitt is: 101111010

References:-

 www.wikipedia.com
 www.google.com

EXPERIMENT NO. 11

IMPLEMENTATION OF CYCLIC REDUNDANCY CHECK(CRC)

A CRC is an error-detecting code. Its computation resembles a polynomial long division


operation in which the quotient is discarded and the remainder becomes the result, with the
important distinction that the polynomial coefficients are calculated according to the carry-
less arithmetic of a finite field. The length of the remainder is always less than the length of
the divisor (called the generator polynomial), which therefore determines how long the result
can be. The definition of a particular CRC specifies the divisor to be used, among other
things.

Typically, an n-bit CRC, applied to a data block of arbitrary length, will detect any single
error burst not longer than n bits (in other words, any single alteration that spans no more
than n bits of the data), and will detect a fraction 1−2 −n of all longer error bursts. Errors in
both data transmission channels and magnetic storage media tend to be distributed non-
randomly making CRCs' properties more useful than alternative schemes such as multiple
parity checks.

The simplest error-detection system, the parity bit, is in fact a trivial 1-bit CRC: it uses the
generator polynomial x+1.

CODE:

#include<stdio.h>
#include<math.h>
#include<conio.h>
int decm1(int,int *);
int decm(int,int *);
int rx[20];
void main()
{
int n,num,gx[20],dx[30],fx[20],i;
int app,k,m,no,val,j;
clrscr();
printf("Enter length of dx: ");
scanf("%d",&m);
printf("Enter the value of dx: ");  
for(i=0;i<m;i++)
{
scanf("%d",&dx[i]);
}
printf("\nEnter length of gx: ");  
scanf("%d",&n);
printf("\nEnter the value of gx: ");  
for(i=0;i<n;i++)
{
scanf("%d",&gx[i]);
}
app=n-1;
k=m+app;
for(i=m;i<k;i++)
dx[i]=0;
printf("\nMODIFIED VALUE OF BITS TO BE TRANSMITTED: ");
for(i=0;i<k;i++)
printf("%d",dx[i]);
no=k-n;
for(i=0;i<n;i++) {
if (gx[i]==dx[i])
rx[i]=0;
else
rx[i]=1;
}
while(no!=0)
{
rx[n]=dx[i];
if(rx[1]==0)
{
for(j=0;j<n;j++)
fx[j]=0;
for(j=0;j<n;j++)
{
if (fx[j]==rx[j+1])
rx[j]=0;
else
rx[j]=1;
}
printf("\n");
for(j=0;j<n;j++)
printf("%d",rx[j]);
}
else
{
for(j=0;j<n;j++)
{
if (gx[j]==rx[j+1])
rx[j]=0;
else
rx[j]=1;
}
printf("\n");
for(j=0;j<n;j++)
printf("%d",rx[j]);
}
no--;
i++;
}
printf("CRC BITS");
num=n;
for(i=k-1;i>0;i--)
{
num--;
if(num>0)
{
if(dx[i]==rx[num])
dx[i]=0;
else
dx[i]=1;
}
}
printf("\nTranssmitted bits: ");
for(i=0;i<k;i++)
printf("%d",dx[i]);  

for(i=0;i<n; i++)
{
if (gx[i]==dx[i])
rx[i]=0;
else
rx[i]=1;
}
for(i=0;i<n;i++)
printf("%d",rx[i]);
no=k-n;
while(no!=0)
{
rx[n]=dx[i];
if(rx[1]==0)
{
for(j=0;j<n;j++)
fx[j]=0;
for(j=0;j<n;j++)
{
if (fx[j]==rx[j+1])
rx[j]=0;
else
rx[j]=1;
}
printf("\n");
for(j=0;j<n;j++)
printf("%d",rx[j]);
}
else
{
for(j=0;j<n;j++)
{
if (gx[j]==rx[j+1])
rx[j]=0;
else
rx[j]=1;
}
printf("\n");
for(j=0;j<n;j++)
printf("%d",rx[j]);
}
no--;
i++;
}
printf("\nremainder bits:");
for(i=0;i<n;i++)
printf("%d",rx[i]);
for(i=0;i<n;i++)
{
if (rx[i]==0)
val=0;
else
val=1;
}
if(val==0)
printf("\n NO ERROR IN TRANSMISSION:");
else
printf("\n ERROR IN TRANSMISSION: ");
getch();
}

OUTPUT:

Enter length of dx: 3

Enter the value of dx: 1101

1111

1010

Enter length of gx: 2

Enter the value of gx: 1101

MODIFIED VALUE OF BITS TO BE TRANSMITTED: 110111111010011


11CRC BITS

Transsmitted bits: 110111111010101

11

10

remainder bits:10

NO ERROR IN TRANSMISSION

References:-

 www.wikipedia.com
 www.google.com

EXPERIMENT NO. 12

IMPLEMENTATION OF HAMMING CODE

In telecommunication, a Hamming code is a linear error-correcting code named after its


inventor, Richard Hamming. Hamming codes can detect up to two simultaneous bit errors,
and correct single-bit errors; thus, reliable communication is possible when the Hamming
distance between the transmitted and received bit patterns is less than or equal to one. By
contrast, the simple parity code cannot correct errors, and can only detect an odd number of
errors...

In mathematical terms, Hamming codes are a class of binary linear codes. For each integer
m>=2 there is a code with m parity bits and 2m − m − 1 data bits. The parity-check matrix of
a Hamming code is constructed by listing all columns of length m that are pairwise
independent. Hamming codes are an example of perfect codes, codes that exactly match the
theoretical upper bound on the number of distinct code words for a given number of bits and
ability to correct errors.

Because of the simplicity of Hamming codes, they are widely used in computer memory
(RAM). In particular, a single-error-correcting and double-error-detecting variant commonly
referred to as SECDED.

CODE:

#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()
{

clrscr();

int a[30];

int n,t,r,b,c,j,i;

cout<<"Enter the no. of message bits";

cin>>b;

for(r=1;;r++)

if((int)pow(2,r)>=(b+r+1))

break;

n=r-1;

cout<<"Enter the message bits";

for(t=(b+r);t>0;t--)

if((int)pow(2,n)!=t)

cin>>a[t];

else

a[t]=9;

n--;

cout<<"The message to be encoded is\n";

for(t=(b+r);t>0;t--)
if(a[t]!=9)

cout<<a[t];

cout<<"\n";

t=b+r;

while(r>0)

r--;

n=(int)pow(2,r);

j=n;

c=0;

while(j<=t)

for(i=1;i<=n&&j<=t;i++)

if(a[j++]==1)

c++;

for(i=1;i<=n&&j<=t;i++)

j++;

a[n]=(((c%2)==0)?0:1);

cout<<"The message after encoding using hamming code is:\n";

for(i=t;i>0;i--)

cout<<a[i];
getch();

OUTPUT:

Enter the number of bits 5

Enter the message bits

11010

11110

10101

11001

10110

The message to be encoded is

1101011110101011100110110

The message after encoding using hamming code is:

11010011110101011100101011000

References:-

 www.wikipedia.com
 www.google.com

Вам также может понравиться