Sunday, August 7, 2011
Tuesday, August 2, 2011
java code for crc-12 and crc-16
import java.io.*;
import java.util.*;
class Crc
{
public char find(char c,char d)
{
if(c=='0'&&d=='0')
return '0';
else if(c=='0'&&d=='1')
return '1';
else if(c=='1'&&d=='0')
return '1';
else
return '0';
}
public static void main(String[] args)throws IOException
{
String s1;
Scanner p=new Scanner(System.in);
System.out.println("enter the original data bits");
s1=p.next();
int l1=s1.length();
System.out.println("menu\n1.crc-12\n2.crc-16");
System.out.println("enter the choice");
int ch=p.nextInt();
String s2="";
if(ch==1)
{
s2="000000000000";
}
else if(ch==2)
{
s2="0000000000000000000";
}
int l2=s2.length();
System.out.println("enter the polynomial coefficient");
String s3=p.next();
int l3=s3.length();
String s4="";
s4=s1+s2;
int l4=s4.length();
int i,j,m;
char a[]=new char[l4];
for(i=0;i<l4;i++)
{
a[i]=s4.charAt(i);
}
char b[]=new char[l3];
Crc cr=new Crc();
char temp[]=new char[100];
for(i=0;i<l3;i++)
{
temp[i]=cr.find(a[i],b[i]);
}
for(i=0;i<l4-l3;i++)
{
for(j=0;j<l3-1;j++)
{
temp[i]=temp[j+1];
}
temp[j]=a[l3+1];
if(temp[0]=='0')
{
for(m=0;m<l3;m++)
{
temp[m]=cr.find(temp[m],'0');
}
}
else
{
for(m=0;m<l3;m++)
{
temp[m]=cr.find(temp[m],b[m]);
}
}
}
System.out.println("transmitted frame:");
for(i=1,j=1;i<l4;i++)
{
a[i]=temp[j];
j++;
}
for(i=0;i<l4;i++)
{
System.out.print(+a[i]);
}
for(i=0;i<l4-l3;i++)
{
for(j=0;j<l3-1;j++)
{
temp[i]=cr.find(a[i],b[i]);
}
temp[j]=a[l3+1];
if(temp[0]=='0')
{
for(m=0;m<l3;m++)
{
temp[m]=cr.find(temp[m],'0');
}
}
else
{
for(m=0;m<l3;m++)
{
temp[m]=cr.find(temp[m],b[m]);
}
}
}
int count=0;
for(i=0;i<l3;i++)
if(temp[i]=='0')
count++;
if(count==l3)
System.out.println("\ntransmitted code is error free");
else
System.out.println("\n it is an error");
}
}
import java.util.*;
class Crc
{
public char find(char c,char d)
{
if(c=='0'&&d=='0')
return '0';
else if(c=='0'&&d=='1')
return '1';
else if(c=='1'&&d=='0')
return '1';
else
return '0';
}
public static void main(String[] args)throws IOException
{
String s1;
Scanner p=new Scanner(System.in);
System.out.println("enter the original data bits");
s1=p.next();
int l1=s1.length();
System.out.println("menu\n1.crc-12\n2.crc-16");
System.out.println("enter the choice");
int ch=p.nextInt();
String s2="";
if(ch==1)
{
s2="000000000000";
}
else if(ch==2)
{
s2="0000000000000000000";
}
int l2=s2.length();
System.out.println("enter the polynomial coefficient");
String s3=p.next();
int l3=s3.length();
String s4="";
s4=s1+s2;
int l4=s4.length();
int i,j,m;
char a[]=new char[l4];
for(i=0;i<l4;i++)
{
a[i]=s4.charAt(i);
}
char b[]=new char[l3];
Crc cr=new Crc();
char temp[]=new char[100];
for(i=0;i<l3;i++)
{
temp[i]=cr.find(a[i],b[i]);
}
for(i=0;i<l4-l3;i++)
{
for(j=0;j<l3-1;j++)
{
temp[i]=temp[j+1];
}
temp[j]=a[l3+1];
if(temp[0]=='0')
{
for(m=0;m<l3;m++)
{
temp[m]=cr.find(temp[m],'0');
}
}
else
{
for(m=0;m<l3;m++)
{
temp[m]=cr.find(temp[m],b[m]);
}
}
}
System.out.println("transmitted frame:");
for(i=1,j=1;i<l4;i++)
{
a[i]=temp[j];
j++;
}
for(i=0;i<l4;i++)
{
System.out.print(+a[i]);
}
for(i=0;i<l4-l3;i++)
{
for(j=0;j<l3-1;j++)
{
temp[i]=cr.find(a[i],b[i]);
}
temp[j]=a[l3+1];
if(temp[0]=='0')
{
for(m=0;m<l3;m++)
{
temp[m]=cr.find(temp[m],'0');
}
}
else
{
for(m=0;m<l3;m++)
{
temp[m]=cr.find(temp[m],b[m]);
}
}
}
int count=0;
for(i=0;i<l3;i++)
if(temp[i]=='0')
count++;
if(count==l3)
System.out.println("\ntransmitted code is error free");
else
System.out.println("\n it is an error");
}
}
Sunday, July 31, 2011
java code for character count framing........
import java.io.*;
import java.util.*;
class Charcount
{
public static void main(String args[])
{
Scanner k=new Scanner(System.in);
System.out.print("enter a string\t");
String str=k.next();
Character c = new Character(str.charAt(0));
String s = c.toString();
int p = Integer.parseInt(s);
int i;
int m=str.length();
for(i=0;(p+i)<=m;)
{
if(p==((str.substring(i,p+i).length())))
{
Character c1 = new Character(str.charAt(p));
String s1 = c1.toString();
i+=p;
p=Integer.parseInt(s1);
}
}
if(i==m)
{
System.out.println("the bits are received correctly");
}
else
{
System.out.println("not received correctly");
}
}
}
import java.util.*;
class Charcount
{
public static void main(String args[])
{
Scanner k=new Scanner(System.in);
System.out.print("enter a string\t");
String str=k.next();
Character c = new Character(str.charAt(0));
String s = c.toString();
int p = Integer.parseInt(s);
int i;
int m=str.length();
for(i=0;(p+i)<=m;)
{
if(p==((str.substring(i,p+i).length())))
{
Character c1 = new Character(str.charAt(p));
String s1 = c1.toString();
i+=p;
p=Integer.parseInt(s1);
}
}
if(i==m)
{
System.out.println("the bits are received correctly");
}
else
{
System.out.println("not received correctly");
}
}
}
Monday, July 25, 2011
guyys.....just try it out :)
1. Which operator has the least priority?
a) Semicolon
b) Assignment
c) Comma
d) Conditional
2. What is the value of j in the following expression?
i=1;
j=i<<1%2;
a) –2
b) 2
c) 10
d) 0
3. What is the value of ‘ i ‘ in the following expression?
i=1;
i=(i<<=1%2)
a) 2
b) 1
c) syntax error
d) 0
4. From the following code
char a,b;
scanf(“%c %s”,&a,&b);
What are the values assigned to a and b, if x and y are given as inputs?
a) a=x and b=blank
b) a=x and b is not assigned
c) a=x and b=y
d) a=x and b=x
5. From the following code:
int i=20;
printf(“%x”,i);
What will be the output of the above printf statement?
a) x14
b) 14
c) 20
d) none of the above
6.
main()
{
int i=0;
for(; ++i;)
printf(“%d”,i);
}
How many times the for loop is executed
a) 0
b) 32767
c) infinite
d) The maximum unsigned integer value
7. The minimum number of inputs and outputs for a program are
a) 0,0
b) 0,1
c) 1,0
d) 1,1
8. The purpose of main () function in a C program is to
a) Initialize all variables
b) Accommodate all input/output statements
c) Initialize necessary variable and open/close files
d) Initialize necessary variables, open/close files and maintain the overall control structures
9. Which of the following are the valid character constants?
a) ‘\n’
b) ‘\\’
c) ‘\0\’
d) All the above
10. What would be the value of x after executing the following program segment?
int x,y=10; char t=’b’;
x=y+t;
a) 108
b) 10
c) 12
d) Error
11. Given a=5, b=6
What is the value of c, if C=a++ + ++b;
a) 11
b) 12
c) 10
d) 13
12. What is the output of the following statements ?
int n=64;
printf(“%04d”,n);
a) 64
b) 6400
c) 0064
d) none of the above
13. What will be the values of a, b and c printed out to the display from the following statements ?
scanf(“%2d %*d %d”,&a,&b,&c);
printf(“a=%d,b=%d,c=%d”,a,b,c);
when the values entered are 1004, 25, 64.
a) a=10, b=25, c= garbage value
b) a=10, b=4, c=25
c) a=1004, b=25, c=64
d) a=1004, b=64, c=garbage value
14. What is the output of the following program ?
int a=5;
printf(“%d, %d, %d”,a++,a,++a);
a) 5,6,7
b) 5,5,5
c) 6,6,6
d) 7,6,6
15. What would be the output of the following program?
main()
{
int i=32,j=0x20,k,l,m;
k=i j;
l=i & j;
m=k^l;
printf(“%d %d %d %d %d”,i,j,k,l,m);
}
a) 32 32 32 32 0
b) 0 0 0 0 0
c) 0 32 32 32 32
d) 32 32 32 32 32
a) Semicolon
b) Assignment
c) Comma
d) Conditional
2. What is the value of j in the following expression?
i=1;
j=i<<1%2;
a) –2
b) 2
c) 10
d) 0
3. What is the value of ‘ i ‘ in the following expression?
i=1;
i=(i<<=1%2)
a) 2
b) 1
c) syntax error
d) 0
4. From the following code
char a,b;
scanf(“%c %s”,&a,&b);
What are the values assigned to a and b, if x and y are given as inputs?
a) a=x and b=blank
b) a=x and b is not assigned
c) a=x and b=y
d) a=x and b=x
5. From the following code:
int i=20;
printf(“%x”,i);
What will be the output of the above printf statement?
a) x14
b) 14
c) 20
d) none of the above
6.
main()
{
int i=0;
for(; ++i;)
printf(“%d”,i);
}
How many times the for loop is executed
a) 0
b) 32767
c) infinite
d) The maximum unsigned integer value
7. The minimum number of inputs and outputs for a program are
a) 0,0
b) 0,1
c) 1,0
d) 1,1
8. The purpose of main () function in a C program is to
a) Initialize all variables
b) Accommodate all input/output statements
c) Initialize necessary variable and open/close files
d) Initialize necessary variables, open/close files and maintain the overall control structures
9. Which of the following are the valid character constants?
a) ‘\n’
b) ‘\\’
c) ‘\0\’
d) All the above
10. What would be the value of x after executing the following program segment?
int x,y=10; char t=’b’;
x=y+t;
a) 108
b) 10
c) 12
d) Error
11. Given a=5, b=6
What is the value of c, if C=a++ + ++b;
a) 11
b) 12
c) 10
d) 13
12. What is the output of the following statements ?
int n=64;
printf(“%04d”,n);
a) 64
b) 6400
c) 0064
d) none of the above
13. What will be the values of a, b and c printed out to the display from the following statements ?
scanf(“%2d %*d %d”,&a,&b,&c);
printf(“a=%d,b=%d,c=%d”,a,b,c);
when the values entered are 1004, 25, 64.
a) a=10, b=25, c= garbage value
b) a=10, b=4, c=25
c) a=1004, b=25, c=64
d) a=1004, b=64, c=garbage value
14. What is the output of the following program ?
int a=5;
printf(“%d, %d, %d”,a++,a,++a);
a) 5,6,7
b) 5,5,5
c) 6,6,6
d) 7,6,6
15. What would be the output of the following program?
main()
{
int i=32,j=0x20,k,l,m;
k=i j;
l=i & j;
m=k^l;
printf(“%d %d %d %d %d”,i,j,k,l,m);
}
a) 32 32 32 32 0
b) 0 0 0 0 0
c) 0 32 32 32 32
d) 32 32 32 32 32
Friday, July 22, 2011
program code for character stuffing and destuffing in java
import java.io.*;
import java.util.*;
import java.lang.*;
class Charstuff
{
public static void main(String args[])
{
Scanner k =new Scanner (System.in);
System.out.println("enter the string\t");
String s=k.nextLine();
String str1;
String str2="";
int i,m,j;
m=s.length();
System.out.println("original data "+s);
str1="dlestx";
for(i=0;i<=m-1;i++)
{
if((s.charAt(i)=='d')&&(s.charAt(i+1)=='l')&&(s.charAt(i+2)=='e'))
{
str1=str1+"dle";
}
str1=str1+s.substring(i,i+1);
}
str1=str1+"dleetx";
int p=str1.length();
System.out.println("transmitted data "+str1);
for(i=6;i<p-6;i++)
{
if((str1.charAt(i)=='d')&&(str1.charAt(i+1)=='l')&&(str1.charAt(i+2)=='e')&&(str1.charAt(i+3)=='d')&&(str1.charAt(i+4)=='l')&&(str1.charAt(i+5)=='e'))
{
i=i+3;
}
str2=str2+str1.substring(i,i+1);
}
System.out.println("received data is "+str2);
}
}
import java.util.*;
import java.lang.*;
class Charstuff
{
public static void main(String args[])
{
Scanner k =new Scanner (System.in);
System.out.println("enter the string\t");
String s=k.nextLine();
String str1;
String str2="";
int i,m,j;
m=s.length();
System.out.println("original data "+s);
str1="dlestx";
for(i=0;i<=m-1;i++)
{
if((s.charAt(i)=='d')&&(s.charAt(i+1)=='l')&&(s.charAt(i+2)=='e'))
{
str1=str1+"dle";
}
str1=str1+s.substring(i,i+1);
}
str1=str1+"dleetx";
int p=str1.length();
System.out.println("transmitted data "+str1);
for(i=6;i<p-6;i++)
{
if((str1.charAt(i)=='d')&&(str1.charAt(i+1)=='l')&&(str1.charAt(i+2)=='e')&&(str1.charAt(i+3)=='d')&&(str1.charAt(i+4)=='l')&&(str1.charAt(i+5)=='e'))
{
i=i+3;
}
str2=str2+str1.substring(i,i+1);
}
System.out.println("received data is "+str2);
}
}
character stuffing program code in c++
#include<iostream>
#include<cstdio>
using namespace std;
void charc();
int main()
{int choice;
while(1)
{printf("\n\n\n1.character stuffing");
printf("\n\n2.exit");
printf("\n\n\nenter choice");
scanf("%d",&choice);
printf("%d",choice);
if(choice>2)
printf("\n\n invalid option....please renter");
switch(choice)
{case 1:
charc();
break;
case 2:
_exit(0);
}}
system("pause");
return 0;}
void charc()
{
char c[50],d[50],t[50];
int i,m,j;
printf("enter the number of characters\n");
scanf("%d",&m);
printf("\n enter the characters\n");
for(i=0;i<m+1;i++)
{scanf("%c",&c[i]);
}printf("\n original data\n");
for(i=0;i<m+1;i++)
printf("%c",c[i]);
d[0]='d';
d[1]='l';
d[2]='e';
d[3]='s';
d[4]='t';
d[5]='x';
for(i=0,j=6;i<m+1;i++,j++)
{if((c[i]=='d'&&c[i+1]=='l'&& c[i+2]=='e'))
{d[j]='d';
j++;
d[j]='l';
j++;
d[j]='e';
j++;
m=m+3;
}d[j]=c[i];
}m=m+6;
m++;
d[m]='d';
m++;
d[m]='l';
m++;
d[m]='e';
m++;
d[m]='e';
m++;
d[m]='t';
m++;
d[m]='x';
m++;
printf("\n\n transmitted data: \n");
for(i=0;i<m;i++)
{printf("%c",d[i]);
}for(i=6,j=0;i<m-6;i++,j++)
{if(d[i]=='d'&&d[i+1]=='l'&&d[i+2]=='e'&&d[i+3]=='d'&&d[i+4]=='l'&&d[i+5]=='e')
i=i+3;
t[j]=d[i];
}printf("\n\nreceived data:");
for(i=0;i<j;i++)
{printf("%c",t[i]);
}
}
#include<cstdio>
using namespace std;
void charc();
int main()
{int choice;
while(1)
{printf("\n\n\n1.character stuffing");
printf("\n\n2.exit");
printf("\n\n\nenter choice");
scanf("%d",&choice);
printf("%d",choice);
if(choice>2)
printf("\n\n invalid option....please renter");
switch(choice)
{case 1:
charc();
break;
case 2:
_exit(0);
}}
system("pause");
return 0;}
void charc()
{
char c[50],d[50],t[50];
int i,m,j;
printf("enter the number of characters\n");
scanf("%d",&m);
printf("\n enter the characters\n");
for(i=0;i<m+1;i++)
{scanf("%c",&c[i]);
}printf("\n original data\n");
for(i=0;i<m+1;i++)
printf("%c",c[i]);
d[0]='d';
d[1]='l';
d[2]='e';
d[3]='s';
d[4]='t';
d[5]='x';
for(i=0,j=6;i<m+1;i++,j++)
{if((c[i]=='d'&&c[i+1]=='l'&& c[i+2]=='e'))
{d[j]='d';
j++;
d[j]='l';
j++;
d[j]='e';
j++;
m=m+3;
}d[j]=c[i];
}m=m+6;
m++;
d[m]='d';
m++;
d[m]='l';
m++;
d[m]='e';
m++;
d[m]='e';
m++;
d[m]='t';
m++;
d[m]='x';
m++;
printf("\n\n transmitted data: \n");
for(i=0;i<m;i++)
{printf("%c",d[i]);
}for(i=6,j=0;i<m-6;i++,j++)
{if(d[i]=='d'&&d[i+1]=='l'&&d[i+2]=='e'&&d[i+3]=='d'&&d[i+4]=='l'&&d[i+5]=='e')
i=i+3;
t[j]=d[i];
}printf("\n\nreceived data:");
for(i=0;i<j;i++)
{printf("%c",t[i]);
}
}
Monday, January 10, 2011
java code for character stuffing and destuffing
Although using characters to mark the beginning and end of each frame has advantages, mostco mp u te r
networks
cannot afford to reserve characters for use by the network. Instead, the network permits ana pp lica t ion
to transfer arbitrary data values across the network. In particular, an application may choose to send data
that contains one or more occurrences of characters like soh and eot that are used for framing. In
general, to distinguish between data being sent and control information such as frame delimiters, network
systems arrange for the sending side to change the data slightly before it is sent, and then arrange for the
receiving side to restore the original data before passing it to the receiving application.
Thus, although applications using the network can transfer arbitrary data, the network system never
confuses data with control information. Because network systems usually insert bits or bytes to change
data for transmission, the technique is known as data stuffing. The terms character stuffing and byte
stuffing refer to data stuffing used with character orientedha rd wa re, and bit stuffing which is more
common, refers to data stuffing used with bit oriented hardware. To implement byte stuffing, a sender
must scan an entire data block and perform the mapping before any data is sent. Byte stuffing can solve
the problem by reserving a third character to mark occurrences of special characters in the data.
Use reserved characters to indicate the start and end of a frame. For instance, use the two-character
sequence DLE STX (Data-Link Escape, Start of TeXt) to signal the beginning of a frame, and the
sequence DLE ETX (End of TeXt) to flag the frame's end.
Problem: What happens if the two-character sequence DLE ETX happens to appear in the frame itself?
Solution: Use character stuffing; within the frame, replace every occurrence of DLE with the two-character sequence DLE DLE. The receiver reverses the processes, replacing every occurrence of DLE DLE with a single DLE.
Example: If the frame contained ``A B DLE D E DLE'', the characters transmitted over the channel would
be ``DLE STX A B DLE DLE D E DLE DLE DLE ETX''.
Disadvantage: character is the smallest unit that can be operated on; not all architectures are byte
oriented
networks
cannot afford to reserve characters for use by the network. Instead, the network permits ana pp lica t ion
to transfer arbitrary data values across the network. In particular, an application may choose to send data
that contains one or more occurrences of characters like soh and eot that are used for framing. In
general, to distinguish between data being sent and control information such as frame delimiters, network
systems arrange for the sending side to change the data slightly before it is sent, and then arrange for the
receiving side to restore the original data before passing it to the receiving application.
Thus, although applications using the network can transfer arbitrary data, the network system never
confuses data with control information. Because network systems usually insert bits or bytes to change
data for transmission, the technique is known as data stuffing. The terms character stuffing and byte
stuffing refer to data stuffing used with character orientedha rd wa re, and bit stuffing which is more
common, refers to data stuffing used with bit oriented hardware. To implement byte stuffing, a sender
must scan an entire data block and perform the mapping before any data is sent. Byte stuffing can solve
the problem by reserving a third character to mark occurrences of special characters in the data.
Use reserved characters to indicate the start and end of a frame. For instance, use the two-character
sequence DLE STX (Data-Link Escape, Start of TeXt) to signal the beginning of a frame, and the
sequence DLE ETX (End of TeXt) to flag the frame's end.
Problem: What happens if the two-character sequence DLE ETX happens to appear in the frame itself?
Solution: Use character stuffing; within the frame, replace every occurrence of DLE with the two-character sequence DLE DLE. The receiver reverses the processes, replacing every occurrence of DLE DLE with a single DLE.
Example: If the frame contained ``A B DLE D E DLE'', the characters transmitted over the channel would
be ``DLE STX A B DLE DLE D E DLE DLE DLE ETX''.
Disadvantage: character is the smallest unit that can be operated on; not all architectures are byte
oriented
Subscribe to:
Posts (Atom)