-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExp1a-bit-stuffing.cpp
More file actions
59 lines (48 loc) · 865 Bytes
/
Exp1a-bit-stuffing.cpp
File metadata and controls
59 lines (48 loc) · 865 Bytes
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
// Implement Framing technique - Bit Stuffing
#include<iostream>
#include<vector>
using namespace std;
vector<int>bitStuffing(vector<int>arr)
{
int n = arr.size();
vector<int>res;
int i=0;
while(i<n)
{
while(i<n and arr[i] == 0)
{
res.push_back(0);
i++;
}
int count = 0;
while(i<n and arr[i] == 1 and count<5)
{
res.push_back(1);
i++;
count++;
}
if(count==5)
{
res.push_back(0);
}
}
return res;
}
int main()
{
int n;
cout<<"Enter the no. of elements in the array: ";
cin>>n;
vector<int>arr(n);
cout<<"Enter the elements of the array:\n";
for (int i = 0; i < n; i++)
{
cin>>arr[i];
}
vector<int>res = bitStuffing(arr);
cout<<"The array after Bit Stuffing is:\n";
for (int i = 0; i < res.size(); i++)
{
cout<<res[i]<<" ";
}
}