Vous êtes sur la page 1sur 21

INDEX

S.No. 1. 2. 3. 4. 5. 6. 7. 8. 9. Experiments
Write A Program to find the shortest path using Dijkistra algorithm. WAP for finding burst and single bit error in given data. WAP for calculate hamming code for given data. WAP for generating the redundant bit using LRC, VRC technique. WAP for generating the redundant bit using CRC technique. WAP for Bit Stuffing. WAP for generating Even and Odd parity. WAP for encrypt the data using caeser cipher method. Study of RS-232.

Remarks

1. Write A Program to find the shortest path using Dijkistra algotithm.


#include<stdlib.h> #include<iostream.h> #define MAX 10 #define TEMP 0 #define PERM 1 #define infinity 9999 struct node { int predecessor; int dist; int status; }; int adj[MAX][MAX]; int n; void create_graph() { int i,max_edges,origin,destin,wt; cout<<"Enter number of vertices:"; cin>>n; max_edges=n*(n-1); for(i=1;i<max_edges;i++) { cout<<"Enter edge or 0 0 quit:"; cin>>origin>>destin; if((origin==0)&&(destin==0)) break; cout<<"enter weight for this edge:"; cin>>wt; if(origin>n||destin>n||origin<=0||destin<=0) { cout<<"invalid!\n"; i--; } else adj[origin][destin]=wt; } } void display()

{ int i,j; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) cout<<adj[i][j]; cout<<"\n"; } }

int findpath(int s,int d,int path[MAX],int*sdist) { struct node state[MAX]; int i,min,count=0,curret,newdistu,u,v; *sdist=0; for(i=1;i<=n;i++) { state[i].predecessor=0; state[i].dist=infinity; state[i].status=TEMP; } state[s].predecessor=0; state[s].dist=0; state[s].status=PERM; int current=s; while(current!=d) { for(i=1;i<=n;i++) { if(adj[current][i]>0&&state[i].status==TEMP) { int newdist=state[current].dist+adj[current][i]; if(newdist<state[i].dist) { state[i].predecessor=current; state[i].dist=newdist; } } } min=infinity; current=0; for(i=1;i<=n;i++) {

if(state[i].status==TEMP&&state[i].dist<min) { min=state[i].dist; current=i; } } if(current==0) return 0; state[current].status=PERM; } while(current!=0) { count++; path[count]=current; current=state[current].predecessor; } for(i=count;i>1;i--) { u=path[i]; v=path[i-1]; *sdist+=adj[u][v]; } return(count); }

int main() { int i,j; int source,dest; int path[MAX]; int shortdist,count; create_graph(); cout<<"The adjecency matrix is:\n"; display(); while(1) { cout<<"Enter source node(0 to quit):"; cin>>source; cout<<"\nEnter destination node<0 to quti>:"; cin>>dest;

if(source==0||dest==0) exit(1); count=findpath(source,dest,path,&shortdist); if(shortdist!=0) { cout<<"shortest distance is:\n"<<shortdist; cout<"<shortest path is :"; for(i=count;i>1;i--) cout<<"d->"<<path[i]; cout<<"d->"<<path[i]; cout<<"\n"; } else cout<<"There is no path from source to destination node\n"; } }

2. WAP for finding burst and single bit error in given data.
#include<iostream.h> #include<conio.h> #include<stdlib.h> void main() { clrscr(); int a[8],b[8]; int l1,l2; cout<<"\n Enter the transmit data "<<endl; for(int i=0;i<8;i++) cin>>a[i]; cout<<"\n Enter the received data "<<endl; for(i=0;i<8;i++) cin>>b[i]; for(i=0;i<8;i++) { if(a[i]!=b[i]) { cout<<"\n Error found at the position "<<i+1; getch(); exit(1); } } cout<<"\n No error found"; getch(); }

3. WAP for calculate hamming code for given data. #include<iostream.h> #include<conio.h> void main() { int a[7],b[11]; int r1,r2,r3,r4; cout<<"\n Enter the 7 bit data "<<endl; for(int i=0;i<7;i++) { cin>>a[i]; } b[0]=a[0]; b[1]=a[1]; b[2]=a[2]; b[4]=a[3]; b[5]=a[4]; b[6]=a[5]; b[8]=a[6]; b[3]=0; b[7]=0; b[9]=0; b[10]=0; r1=b[10]+b[8]+b[6]+b[4]+b[2]+b[0]; r2=b[9]+b[8]+b[5]+b[4]+b[1]+b[0]; r3=b[7]+b[6]+b[5]+b[4]; r4=b[3]+b[2]+b[1]+b[0]; r1=r1%2; r2=r2%2; r3=r3%2; r4=r4%2; b[3]=r4; b[7]=r3; b[9]=r2; b[10]=r1; cout<<"\n_______________________________________"<<endl;

cout<<"\n Hamming code " <<endl; for(i=0;i<11;i++) { cout<<" "<<b[i] ; } getch(); }

4. WAP for generating the redundant bit using LRC,VRC technique. #include<iostream.h> #include<conio.h> void main() { int a[5][5],b[6][6]; int i,j,s; clrscr(); cout<<"\n Enter 5 5bit data :" <<endl; for(i=0;i<5;i++) for(j=0;j<5;j++) cin>>a[i][j]; cout<<"\n enterd data is " ; for(i=0;i<5;i++) { cout<<"\n"; for(j=0;j<5;j++) cout<<" "<<a[i][j]; }

for(i=0;i<5;i++) for(j=0;j<5;j++) b[i][j]=a[i][j]; for(i=0;i<6;i++) { b[i][5]=0; b[5][i]=0; }

for(i=0;i<6;i++) { s=0; for(j=0;j<6;j++) s=s+b[i][j]; b[i][5]=s%2;

for(i=0;i<6;i++) { s=0; for(j=0;j<6;j++) s=s+b[j][i]; b[5][i]=s%2; }

cout<<"\n _______________________"<<endl; cout<<"\n After adding LRC VRC :"<<endl; for(i=0;i<6;i++) { cout<<"\n"; for(j=0;j<6;j++) cout<<" "<<b[i][j]; } getch(); }

5. WAP for generating the redundant bit using CRC technique. #include<iostream.h> #include<conio.h> void main() { clrscr(); int i,j,n,g,a,arr[20],gen[20],q[20],s; cout<<"Transmitter side:"; cout<<"\nEnter no.of data bits:"; cin>>n; cout<<"\nEnter data:"; for(i=0;i<n;i++) cin>>arr[i]; cout<<"\nEnter size of generator:"; cin>>g; do { cout<<"\nEnter generator:"; for(j=0;j<g;j++) cin>>gen[j]; } while(gen[0]!=1); cout<<"\n\tThe generator matrix:"; for(j=0;j<g;j++) cout<<gen[j]; a=n+g-1; cout<<"\n\tThe appended matrix is:"; for(i=0;i<j;++i) arr[n+i]=0; for(i=0;i<a;++i) cout<<arr[i]; for(i=0;i<n;++i) q[i]=arr[i]; for(i=0;i<n;++i) { if(arr[i]==0) { for(j=i;j<g+i;++j) arr[j]=arr[j]^0; } else { arr[i]=arr[i]^gen[0];

arr[i+1]=arr[i+1]^gen[1]; arr[i+2]=arr[i+2]^gen[2]; arr[i+3]=arr[i+3]^gen[3]; } } cout<<"\n\tThe CRC is:"; for(i=n;i<a;++i) cout<<arr[i]; s=n+a; for(i=n;i<s;i++) q[i]=arr[i]; cout<<"\n"; for(i=0;i<a;i++) cout<<q[i]; getch(); }

6. WAP for Bit Stuffing.

#include<iostream.h> #include<conio.h> void main() { clrscr(); int a[8],b[9]; int i,j,t=0,count=0; b[8]=0; cout<<"\n\n Enter the data "<<endl; for(i=0;i<8;i++) { cin>>a[i]; } for(i=0;i<8;i++) { if(a[i]==0) { b[t]=0; j=i+1; t++; for(j;j<=i+5;j++) { b[t]=a[j]; count++; // cout<<"b["<<t<<"] :"<<b[t]; t++; } if(a[j]==1 && count==5) { b[t]=0; // cout<<"\n b["<<t<<"] "<<b[t]; t++; } i=i+5;

} else { b[t]=1; t++; } } cout<<"\n Stiffing O/P is "<<endl; for(i=0;i<9;i++) { cout<<" "<<b[i] ; } getch(); }

7. WAP for generating Even and Odd parity. #include<iostream.h> #include<conio.h> void main() { clrscr(); int a[8]; int b[9],c[9]; int s=0; cout<<"\n Enter the data (0/1) "<<endl; for(int i=0;i<8;i++) { cin>>a[i]; } for(i=0;i<8;i++) { b[i]=a[i]; c[i]=a[i]; } cout<<"\n Entered data is"<<endl; for(i=0;i<8;i++) cout<<" "<<a[i]; for(i=0;i<8;i++) { s=s+a[i]; } b[8]=s%2; if(s%2==0) c[8]=1; else c[8]=0; cout<<"\n_________________________________________"<<endl; cout<<"\n Even parity data "<<endl; for(i=0;i<9;i++) cout<<" "<<b[i]; cout<<"\n\n Odd parity data is "<<endl;

for(i=0;i<9;i++) cout<<" "<<c[i]; getch(); }

8. WAP for encrypt the data using caeser cipher method. #include<iostream.h> #include<conio.h> #include<stdio.h> int main() { char msg[30],c[30],key[30]; int i,j=0; cout<<"enter msg"; cin>>msg; while(j<=5) { for(i=0;i<=5;i++) { cout<<"enter key for "<<i<<" character"; cin>>key[i]; c[i]=key[i]+msg[j]; j++; } } cout<<"encrypted message is:"<<c; getch(); return(0); }

9. Study of RS-232.

Theory :a series of

In telecommunications, RS-232 (Recommended Standard 232) is the traditional name for


standards for serial binary single-ended data and control signals connecting between

a DTE (Data Terminal Equipment) and a DCE (Data Circuit-terminating Equipment). It is commonly used in computer serial ports. The standard defines the electrical characteristics and timing of signals, the meaning of signals, and the physical size and pinout of connectors.

Fig.:- A 25 pin connector as described in the RS-232 standard

Scope Of The Standard :- The Electronic Industries Association (EIA) standard RS-232c as
of 1969 defines:

Electrical signal characteristics such as voltage levels, signaling rate, timing and slew-rate of signals, voltage withstand level, short-circuit behavior, and maximum load capacitance.

Interface mechanical characteristics, pluggable connectors and pin identification. Functions of each circuit in the interface connector. Standard subsets of interface circuits for selected telecom applications.

The standard does not define such elements as:-

character encoding (for example, ASCII, Baudot code or EBCDIC) the framing of characters in the data stream (bits per character, start/stop bits, parity) protocols for error detection or algorithms for data compression bit rates for transmission, although the standard says it is intended for bit rates lower than 20,000 bits per second.Many modern devices support speeds of 115,200 bit/s and above

power supply to external devices.

Limitations of the standard: -

Because the application of RS-232 has extended far

beyond the original purpose of interconnecting a terminal with a modem, successor standards have been developed to address the limitations. Issues with the RS-232 standard include:

The large voltage swings and requirement for positive and negative supplies increases power consumption of the interface and complicates power supply design. The voltage swing requirement also limits the upper speed of a compatible interface.

Single-ended signaling referred to a common signal ground limits the noise immunity and transmission distance.

Multi-drop connection among more than two devices is not defined. While multi-drop "work-arounds" have been devised, they have limitations in speed and compatibility.

Asymmetrical definitions of the two ends of the link make the assignment of the role of a newly developed device problematic; the designer must decide on either a DTE-like or DCE-like interface and which connector pin assignments to use.

The handshaking and control lines of the interface are intended for the setup and takedown of a dialupcommunication circuit; in particular, the use of handshake lines for flow control is not reliably implemented in many devices.

No method is specified for sending power to a device. While a small amount of current can be extracted from the DTR and RTS lines, this is only suitable for low power devices such as mice.

The 25-way connector recommended in the standard is large compared to current practice.

Standard Details :- In RS-232, user data is sent as a time-series of bits. Both synchronous and
asynchronous transmissions are supported by the standard. In addition to the data circuits, the standard defines a number of control circuits used to manage the connection between the DTE and DCE. Each data or control circuit only operates in one direction, that is, signaling from a DTE to the attached DCE or the reverse. Since transmit data and receive data are separate circuits, the interface can operate in a full duplex manner, supporting concurrent data flow in both directions. The standard does not define character framing within the data stream, or character encoding.

Voltage Levels :The RS-232 standard defines the voltage levels that correspond to logical one and logical zero levels for the data transmission and the control signal lines. Valid signals are plus or minus 3 to 15 volts; the 3 V range near zero volts is not a valid RS-232 level. The standard specifies a maximum open-circuit voltage of 25 volts: signal levels of 5 V, 10 V, 12 V, and 15 V are all commonly seen depending on the power supplies available within a device.

Pinouts :The following table lists commonly-used RS-232 signals and pin assignments.[7] See Serial port for nonstandard variations including the popular DE-9 connector.

Signal Name Typical purpose

DBAbbreviation DTE DCE 25pin


common

Origin

Data Terminal OOB control signal: Tells DCE that DTE is ready to be DTR Ready connected. Data Detect Carrier OOB control signal: Tells DTE that DCE is connected DCD to telephone line. OOB control signal: Tells DTE that DCE is ready to DSR receive commands or data. OOB control signal: Tells DTE that DCE has detected a RI ring signal on the telephone line. OOB control signal: Tells DCE to prepare to accept RTS data from DTE. OOB control signal: Acknowledges RTS and allows CTS DTE to transmit. Data signal: Carries data from DTE to DCE. Data signal: Carries data from DCE to DTE. TxD RxD GND PG

20 8 6 22 4 5 2 3 7 1

Data Set Ready Ring Indicator Request To Send Clear To Send Transmitted Data Received Data Common Ground Protective Ground

common

The signals are named from the standpoint of the DTE. The ground signal is a common return for the other connections. The DB-25 connector includes a second "protective ground" on pin 1. Connecting this to pin 7 (signal reference ground) is a common practice but not essential. Data can be sent over a secondary channel (when implemented by the DTE and DCE devices), which is equivalent to the primary channel. Pin assignments are described in following table:

Signal Common Ground

Pin 7 (same as primary)

Secondary Transmitted Data (STD) 14 Secondary Received Data (SRD) 16

Secondary Request To Send (SRTS) 19 Secondary Clear To Send (SCTS) Secondary Carrier Detect (SDCD) 13 12

Cables :The standard does not define a maximum cable length but instead defines the maximum capacitance that a compliant drive circuit must tolerate. A widely-used rule-of-thumb indicates that cables more than 50 feet (15 metres) long will have too much capacitance, unless special cables are used. By using low-capacitance cables, full speed communication can be maintained over larger distances up to about 1,000 feet. For longer distances, other signal standards are better suited to maintain high speed. Since the standard definitions are not always correctly applied, it is often necessary to consult documentation, test connections with a breakout box, or use trial and error to find a cable that works when interconnecting two devices. Connecting a fully-standard-compliant DCE device and DTE device would use a cable that connects identical pin numbers in each connector (a so-called "straight cable"). "Gender changers" are available to solve gender mismatches between cables and connectors. Connecting devices with different types of connectors requires a cable that connects the corresponding pins according to the table above. Cables with 9 pins on one end and 25 on the other are common. Manufacturers of equipment with 8P8C connectors usually provide a cable with either a DB-25 or DE-9 connector (or sometimes interchangeable connectors so they can work with multiple devices). Poor-quality cables can cause false signals by crosstalk between data and control lines (such as Ring Indicator). If a given cable will not allow a data connection, especially if a Gender changer is in use, aNull modem may be necessary.

RTS/CTS Handshaking :In older versions of the specification, RS-232's use of the RTS and CTS lines is asymmetric: The DTE asserts RTS to indicate a desire to transmit to the DCE, and the DCE asserts CTS in response to grant permission. This allows for half-duplex modems that disable their transmitters when not required, and must transmit a synchronization preamble to the receiver when they are re-enabled. This scheme is also employed on present-day RS-232 to RS-485 converters, where the RS-232's RTS signal is used to ask the converter to take control of the RS-485 bus - a concept that doesn't otherwise exist in RS-232. There is no way for the DTE to indicate that it is unable to accept data from the DCE. A non-standard symmetric alternative, commonly called "RTS/CTS handshaking," was developed by various equipment manufacturers: CTS indicates permission from the DCE for the DTE to send data to the DCE (and is controlled by the DCE independent of RTS), and RTS indicates permission from the DTE for the DCE to send data to the DTE. This was eventually codified in version RS-232-E (actually TIA-232-E by that time) by defining a new signal, "RTR (Ready to Receive)," which is CCITT V.24 circuit 133. TIA-232-E and the corresponding international standards were updated to show that circuit 133, when implemented, shares the same pin as RTS (Request to Send), and that when 133 is in use, RTS is assumed by the DCE to be ON at all times.

Vous aimerez peut-être aussi