0% found this document useful (0 votes)
41 views

Ass2 15 23

The host command is used to perform DNS lookups and convert names to IP addresses and vice versa. It prints a short summary of its arguments and options when no arguments are given. The "name" argument specifies the domain name to look up, which can be an IP address to perform a reverse lookup. The optional "server" argument specifies an alternate name server to query other than the default server(s) listed in the resolv.conf file.

Uploaded by

kemal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Ass2 15 23

The host command is used to perform DNS lookups and convert names to IP addresses and vice versa. It prints a short summary of its arguments and options when no arguments are given. The "name" argument specifies the domain name to look up, which can be an IP address to perform a reverse lookup. The optional "server" argument specifies an alternate name server to query other than the default server(s) listed in the resolv.conf file.

Uploaded by

kemal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

10 host name command

host is a simple utility for performing DNS lookups. It is normally used to convert names to IP addresses
and vice versa. When no arguments or options are given, host prints a short summary of its command
line arguments and options.

name is the domain name that is to be looked up. It can also be a dotted-decimal IPv4 address or a
colon-delimited IPv6
address, in which case host will by default perform a reverse lookup for that address. server is an
optional argument
which is either the name or IP address of the name server that host should query instead of the server
or servers listed in /etc/resolv.conf.

ASSESSMENT-2
DATE 6/8/2019

1. Even and Odd Parity Generator

ALGORITH

Algorithm: getParity(n)
1. Initialize parity = 0
2. Loop while n != 0
a. Invert parity
parity = !parity
b. Unset rightmost set bit
n = n & (n-1)
3. return parity

CODE
# include <stdio.h>
# define bool int

/* Function to get parity of number n. It returns 1


if n has odd parity, and returns 0 if n has even
parity */
bool getParity(unsigned int n)
{
bool parity = 0;
while (n)
{
parity = !parity;
n = n & (n - 1);
}
return parity;
}

/* Driver program to test getParity() */


int main()
{
unsigned int n = 7;
printf("Parity of no %d = %s", n,
(getParity(n)? "odd": "even"));

getchar();
return 0;
}

OUTPUT

2. Checksum

Checksum Algorithm

1. Take 2 binary input strings.


2. Do their binary sum to find out the checksum which will be sent to the destination or to the
receiver.
3. In binary sum there are 6 cases:-
a. If both bits are 0 and carry is 0, sum=0 and carry=0
b. If both bits are 0 and carry is 1, sum=1 and carry=0
c. If both bits are 1 and carry is 0, sum=0 and carry=1
d. If both bits are 1 and carry is 1, sum=1 and carry=1
e. If either bit is 1 and carry is 0, sum=1 and carry=0
f. If either bit is 1 and carry is 1, sum=0 and carry=1
4. While doing the addition we have to add the binary strings from rightmost end i.e LSB to MSB.
5. When binary sum is done 1’s complement of it is taken by reversing 1’s to 0’s and vice versa.
6. The resulting 1’s complement is the Checksum.
7. Stop.
CODE
#include<stdio.h>
#include<string.h>

int main()
{
char a[20],b[20];
char sum[20],complement[20];
int i,length;

printf("Enter first binary string\n");


scanf("%s",&a);
printf("Enter second binary string\n");
scanf("%s",&b);

if(strlen(a)==strlen(b)){
length = strlen(a);
char carry='0';

for(i=length-1;i>=0;i--)
{
if(a[i]=='0' && b[i]=='0' && carry=='0')
{
sum[i]='0';
carry='0';
}
else if(a[i]=='0' && b[i]=='0' && carry=='1')
{
sum[i]='1';
carry='0';

}
else if(a[i]=='0' && b[i]=='1' && carry=='0')
{
sum[i]='1';
carry='0';

}
else if(a[i]=='0' && b[i]=='1' && carry=='1')
{
sum[i]='0';
carry='1';

}
else if(a[i]=='1' && b[i]=='0' && carry=='0')
{
sum[i]='1';
carry='0';

}
else if(a[i]=='1' && b[i]=='0' && carry=='1')
{
sum[i]='0';
carry='1';

}
else if(a[i]=='1' && b[i]=='1' && carry=='0')
{
sum[i]='0';
carry='1';

}
else if(a[i]=='1' && b[i]=='1' && carry=='1')
{
sum[i]='1';
carry='1';

}
else
break;
}

printf("\nSum=%c%s",carry,sum);

for(i=0;i<length;i++)
{
if(sum[i]=='0')
complement[i]='1';
else
complement[i]='0';
}

if(carry=='1')
carry='0';
else
carry='1';

printf("\nChecksum=%c%s",carry,complement);
}
else {
printf("\nWrong input strings");
}
}
OUTPUT

3. Cyclic Redundancy Check

ALGORITHM
Algorithm 1:

for (i = 1; i<=Message_Length; i++)


{
set all bits in the Message to 0
change the i'th bit to 1
calculate the checksum (cs)
EC_table[cs] = i
}

CODE

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
int i,j,keylen,msglen;
char input[100], key[30],temp[30],quot[100],rem[30],key1[30];
clrscr();
printf("Enter Data: ");
gets(input);
printf("Enter Key: ");
gets(key);
keylen=strlen(key);
msglen=strlen(input);
strcpy(key1,key);
for(i=0;i<keylen-1;i++)
{
input[msglen+i]='0';
}
for(i=0;i<keylen;i++)
temp[i]=input[i];
for(i=0;i<msglen;i++)
{
quot[i]=temp[0];
if(quot[i]=='0')
for(j=0;j<keylen;j++)
key[j]='0';
else
for(j=0;j<keylen;j++)
key[j]=key1[j];
for(j=keylen-1;j>0;j--)
{
if(temp[j]==key[j])
rem[j-1]='0';
else
rem[j-1]='1';
}
rem[keylen-1]=input[i+keylen];
strcpy(temp,rem);
}
strcpy(rem,temp);
printf("\nQuotient is ");
for(i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for(i=0;i<keylen-1;i++)
printf("%c",rem[i]);
printf("\nFinal data is: ");
for(i=0;i<msglen;i++)
printf("%c",input[i]);
for(i=0;i<keylen-1;i++)
printf("%c",rem[i]);
getch();
}
OUTPUT

4. Hamming Code

Algorithm

1. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).
2. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).
3. All the other bit positions are marked as data bits.
4. Each data bit is included in a unique set of parity bits, as determined its bit position in binary
form.
a. Parity bit 1 covers all the bits positions whose binary representation includes a 1 in the
least significant
position (1, 3, 5, 7, 9, 11, etc).
b. Parity bit 2 covers all the bits positions whose binary representation includes a 1 in the
second position from
the least significant bit (2, 3, 6, 7, 10, 11, etc).
c. Parity bit 4 covers all the bits positions whose binary representation includes a 1 in the
third position from
the least significant bit (4–7, 12–15, 20–23, etc).
d. Parity bit 8 covers all the bits positions whose binary representation includes a 1 in the
fourth position from
the least significant bit bits (8–15, 24–31, 40–47, etc).
e. In general each parity bit covers all bits where the bitwise AND of the parity position and
the bit position is
non-zero.
5. Since we check for even parity set a parity bit to 1 if the total number of ones in the positions
it checks is
odd.
6. Set a parity bit to 0 if the total number of ones in the positions it checks is even.

CODE

#include<stdio.h>
void main()
{
int data[10];
int dataatrec[10],c,c1,c2,c3,i;

printf("Enter 4 bits of data one by one\n");


scanf("%d",&data[0]);
scanf("%d",&data[1]);
scanf("%d",&data[2]);
scanf("%d",&data[4]);

//Calculation of even parity


data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4];
data[3]=data[0]^data[1]^data[2];

printf("\nEncoded data is\n");


for(i=0;i<7;i++)
printf("%d",data[i]);

printf("\n\nEnter received data bits one by one\n");


for(i=0;i<7;i++)
scanf("%d",&dataatrec[i]);

c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];
c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];
c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];
c=c3*4+c2*2+c1 ;

if(c==0) {
printf("\nNo error while transmission of data\n");
}
else {
printf("\nError on position %d",c);

printf("\nData sent : ");


for(i=0;i<7;i++)
printf("%d",data[i]);

printf("\nData received : ");


for(i=0;i<7;i++)
printf("%d",dataatrec[i]);

printf("\nCorrect message is\n");

//if errorneous bit is 0 we complement it else vice versa


if(dataatrec[7-c]==0)
dataatrec[7-c]=1;
else
dataatrec[7-c]=0;

for (i=0;i<7;i++) {
printf("%d",dataatrec[i]);
}
}
}

OUTPUT

You might also like