-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.Byte_Stuffing.c
More file actions
78 lines (68 loc) · 1.91 KB
/
10.Byte_Stuffing.c
File metadata and controls
78 lines (68 loc) · 1.91 KB
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
#include <stdio.h>
#include <string.h>
int data_to_binary(int n)
{
int output = 0, place = 1, rem;
while (n > 0)
{
rem = n % 2;
output = output + (place * rem);
n = n / 2;
place = place * 10;
}
return output;
}
int main()
{
int i;
char data[10], Flag[9] = "00011011", ESC[9] = "11111110";
printf("Enter the original data: ");
scanf("%s", data);
puts("\nData Existing at Network Layer of the source node is:");
for (i = 0; i < strlen(data); ++i)
{
printf("%08d ", data_to_binary(data[i]));
}
puts("\n\nData Existing at Data Link Layer of the source node is:");
printf("%s ", ESC);
for (i = 0; i < strlen(data); ++i)
{
if ((i + 1) % 2 == 0)
{
printf("%s ", Flag);
}
printf("%08d ", data_to_binary(data[i]));
}
printf("%s\n", ESC);
puts("\nData Received at Data Link Layer of the source node is:");
printf("%s ", ESC);
for (i = 0; i < strlen(data); ++i)
{
if ((i + 1) % 2 == 0)
{
printf("%s ", Flag);
}
printf("%08d ", data_to_binary(data[i]));
}
printf("%s\n", ESC);
puts("\nData Received at Network Layer of the destination node is:");
for (i = 0; i < strlen(data); ++i)
{
printf("%08d ", data_to_binary(data[i]));
}
return 0;
}
// Input/Output:
// Enter the original data: apple
//
// Data Existing at Network Layer of the source node is:
// 01100001 01110000 01110000 01101100 01100101
//
// Data Existing at Data Link Layer of the source node is:
// 11111110 01100001 00011011 01110000 01110000 00011011 01101100 01100101 11111110
//
// Data Received at Data Link Layer of the source node is:
// 11111110 01100001 00011011 01110000 01110000 00011011 01101100 01100101 11111110
//
// Data Received at Network Layer of the destination node is:
// 01100001 01110000 01110000 01101100 01100101