Network and Communication Kunal Singh 18BCI0189 Lab Da - 1
Network and Communication Kunal Singh 18BCI0189 Lab Da - 1
Kunal Singh
18BCI0189
LAB DA -1
Output:
Code:
Odd parity:
clc;
close all;
clear all;
tic()
x = input('Enter the bit sequence to test for Odd parity: ');
t = 0;
for i = 1:length(x) %can replace this 'for' loop just by t=sum(x)
if(x(i))
t = t + 1; %increment by one if a bit is one
end
end
if(mod(t,2)~=1) %check if not odd then attach another '1' to make the parity
odd
y = [x 1]; disp('Parity bit generated : 1');
else %check if odd then attach another '0' to let the parity be odd
y = [x 0]; disp('Parity bit generated : 0');
end
disp('Input bit sequence:');
disp(x); %display the input bit sequence
disp('Bit sequence with parity (Odd) bit : ');
disp(y);%display the resultant bit sequence after parity bit addition
toc()
Output: