Sem 5‎ > ‎

### DCCN LAB Subscribe to posts

#### 00 All you need to know.

posted Nov 6, 2012, 5:51 PM by Neil Mathew

 Awesome PDFs. Summarized Content.http://users.ecs.soton.ac.uk/sqc/EL336/CNL-11.pdf

#### P-3 WAP to generate Hamming Code.

posted Nov 6, 2012, 8:50 AM by Neil Mathew

 SOURCE CODE:```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 #include //#include   using namespace std;   // HAMMING CODE FOR 4-bit data. 2^2 => 2 + 1 = 3 // Error detection bits req = 3 // Total bits required = 4 + 3 = 7 bits   // R holding the error detection bits. // 2^0 = 1 // 2^1 = 2 // 2^2 = 4   // Frame: d7 d6 d5 r4 d3 r2 r1   int i=0; int d3, d5, d6, d7; int r1, r2, r4;     void sender() {         cout<<" Enter the 4-bit word: ";         cin>>d7;         cin>>d6;         cin>>d5;         cin>>d3;   // What all positions it affects: // r1: 1, 3, 5, 7 // r2: 2, 3, 6, 7 // r4: 4, 5, 6, 7   // Then, check whether it contains even number of 1s or not. // If even, put 0, else put 1.           r1= (d3 + d5 + d7) %2;         r2= (d3 + d6 + d7) %2;         r4= (d5 + d6 + d7) %2;   // FRAME:         int frame[] = { r1, r2, d3, r4, d5, d6, d7 };           cout <<"\n The code at SENDER is: ";         for(i=6; i>=0; i--)         cout<=0; i--)         cin>>frame[i];           d7 = frame;         d6 = frame;         d5 = frame;         r4 = frame;         d3 = frame;         r2 = frame;         r1 = frame;   // What all positions Rs it affects: // r1: 1, 3, 5, 7 // r2: 2, 3, 6, 7 // r4: 4, 5, 6, 7           //If not even         r1= (r1 + d3 + d5 + d7) %2;         r2= (r2 + d3 + d6 + d7) %2;         r4= (r4 + d5 + d6 + d7) %2;   //Find position by converting binary no r4 r2 r1 to decimal           int dec=0;           if( r1 == 0 && r2 == 0 && r4 == 0 )         cout<<" No Errors. Message is = "<

#### P-2 WAP to determine if the IP address is in Class A, B, C, D, or E.

posted Nov 6, 2012, 5:58 AM by Neil Mathew   [ updated Nov 6, 2012, 6:00 AM ]

 SOURCE CODE:```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 #include   using namespace std;   /*      CLASSES           A:        0 - 127 ( = 128 )         B:      128 - 191 ( = 64 )         C:      192 - 223 ( =  32 )         D:      224 - 239 ( = 16 )         E:      240 - 255 ( = 16 ) */     int main()         { //      clrscr();           int a,i=0;           cout<<"Enter The IP address";         for(i=0;i<4;i++)                 cin>>a[i];           cout<<"\n IP ADDRESS:"<=0 && a<=127)         cout<<"Class A";         if(a>127 && a<191)         cout<<"Class B";         if(a>191 && a<224)         cout<<"Class C";         if(a>224 && a<=239)         cout<<"Class D";         if(a>239)         cout<<"Class E";   //      getch();           return 1;         }  ```OUTPUT:```Enter The IP address 220 100 8 12 IP ADDRESS:220.100.8.12 The IP address is in Class: Class C```

#### 02 IP Addresses? Their Classes.

posted Nov 6, 2012, 5:47 AM by Neil Mathew   [ updated Nov 6, 2012, 6:12 AM ]

BRIEF INTRO:

IP: Short for Internet ProtocolIP is an address of a computer or other network device on a network using IP or TCP/IP.

There are five classes of available IP ranges: Class A, Class B, Class C, Class D and Class E, while only A, B, and C are commonly used. Each class allows for a range of valid IP addresses. Below is a listing of these addresses.

 Class Address Range Supports Class A 1.0.0.1 to 126.255.255.254 Supports 16 million hosts on each of 127 networks. Class B 128.1.0.1 to 191.255.255.254 Supports 65,000 hosts on each of 16,000 networks. Class C 192.0.1.1 to 223.255.254.254 Supports 254 hosts on each of 2 million networks. Class D 224.0.0.0 to 239.255.255.255 Reserved for multicast groups. Class E 240.0.0.0 to 254.255.255.254 Reserved for future use, or Research and Development Purposes.

Every IP address is broke down into four sets of octets that break down into binary to represent the actual IP address. The below table is an example of the IP 255.255.255.255.

 IP: 255 255 255 255 Binary value: 11111111 11111111 11111111 11111111 Octet value: 8 8 8 8

If we were to break down the IP "166.70.10.23", you would get the below value. In the below table, the first row is the IP address, the second row is the binary values, and the third row shows how the binary value equals the section of the IP address.

 166 70 10 23 10100110 01000110 00001010 00010111 128+32+4+2=166 64+4+2=70 8+2=10 16+4+2+1=23

#### P-1 WAP to translate dotted decimal IP address into 32 bit address.

posted Nov 6, 2012, 5:36 AM by Neil Mathew

SOURCE CODE:

 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 ``` ```#include   using namespace std;   void DEC2BIN(int dec) {         // 128 = 2^7 = 8 bit         //  64 = 2^6 = 7 bit         //  32 = 2^5 = 6 bit         //  16 = 2^4 = 5 bit         //  08 = 2^3 = 4 bit         //  04 = 2^2 = 3 bit         //  02 = 2^1 = 2 bit         //  01 = 2^0 = 1 bit       for (int i = 128; i != 0; i=i>>1)   {     if (dec & i)       cout<<"1";     else       cout<<"0";   }   }     int main()         {           //clrscr();           //DECLARATIONS         int i,j;         int dec;         int bin={128,64,32,16,8,4,2,1};           //INPUT         cout<<"Enter the IP Address: ";         for(i=0;i<4;i++)         cin>>dec[i];           //TRANSLATION         cout<<"The ip address is: "<

OUTPUT:

```Enter the IP Address: 100 125 0 8
01100100.01111101.00000000.00001000```

#### P-0b WAP to convert Binary to Decimal

posted Nov 6, 2012, 12:40 AM by Neil Mathew

 SOURCE CODE:```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 #include   using namespace std;   int pow(int n, int i) { int result=1;   while(i--) { result*=n; }   return result; }     int main() {   int n;     cout<<"Enter A Binary Number: ";   cin>>n;     cout<<"\n BINARY: "< 0);             cout<<"\n DECIMAL: "<

#### P-0 WAP to Convert Decimal to Binary Number

posted Nov 6, 2012, 12:18 AM by Neil Mathew

Source Code

 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ``` ```#include #include void main() {      clrscr();   int n;     cout<<"Enter A Decimal Number: ";   cin>>n;     cout<<"\n DECIMAL: "<>1)   {     if (n & i)       cout<<"1 ";     else       cout<<"0 ";   }     cout<

Output:

```Enter A Decimal Number: 12
DECIMAL: 12
BINARY: 0 0 0 0 1 1 0 0 ```

#### 01 Understanding Bit-wise Operators

posted Nov 5, 2012, 11:49 PM by Neil Mathew   [ updated Nov 6, 2012, 6:11 AM ]

First of all, we need to understand how the bitwise operator works.

Bitwise operators are kind of advanced - they work on the binary bits of numbers.

First, you have bitwise AND(&).
This compares each bit.
If the bits from both of the numbers are 1, then the resulting bit is 1.
Otherwise, the resulting bit is 0.

For example:

56 00111000
235 11101011
&-------------
40 00101000

Next, you have bitwise OR(|)
If either bit is 1, then the resulting bit is 1.

56 00111000
235 11101011
|-------------
251 11111011

Also, you have bitwise XOR(^)
If only one of the bits is 1, then the resulting bit is 1
(if both are 1, or neither are 1, then the resulting bit is 0).

56 00111000
235 11101011
^---------------
211 11010011

The final bitwise operator is bitwise NOT (~).
This works on only one operand - it simply flips the bits.

56 00111000
~-------------
199 11000111

Second, we need to know HOW they can be used.

One main function is the easy conversion of decimal values to binary and vice versa.

We can use two operations to perform a number conversion.
1. Bit-wise AND operation. To compare the bits one by one.
2. Bit-wise Right - Shift Operation. To divide the number by 2.

Depending on the no of bits in the system, we need an initial constant.

For 4-bit numbers, we use 8 (1000)

Each step, we divide this constant by 2 using bit-wise right shift operator >>.
8>>1 = 4
4>>1 = 2
2>>1 = 1

( Operandtoshift >> NoOfTimesDone )

 step-1======1 1 0 0 = 121 0 0 0 = 08&----------- 1 0 0 0 (12 & 8)Not Zero. Print 1. 1 step-2======1 1 0 0 = 120 1 0 0 = 04&-----------0 1 0 0 (12 & 4)Not Zero. Print 1. 1 step-3======1 1 0 0 = 120 0 1 0 = 02&-----------0 0 0 0 (12 & 2)Zero. Print 0. 0 step-4======1 1 0 0 = 120 0 0 1 = 01 &-----------0 0 0 0 (12 & 1)Zero. Print 0. 0

So, Binary equivalent of 12 = 1100

1-8 of 8