summaryrefslogtreecommitdiff
path: root/1241/CH3
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /1241/CH3
downloadScilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip
initial commit / add all books
Diffstat (limited to '1241/CH3')
-rwxr-xr-x1241/CH3/EX3.1/exa3_1.sce55
-rwxr-xr-x1241/CH3/EX3.10/exa3_10.sce57
-rwxr-xr-x1241/CH3/EX3.11/exa3_11.sce76
-rwxr-xr-x1241/CH3/EX3.2/exa3_2.sce66
-rwxr-xr-x1241/CH3/EX3.3/exa3_3.sce40
-rwxr-xr-x1241/CH3/EX3.4/exa3_4.sce40
-rwxr-xr-x1241/CH3/EX3.5/exa3_5.sce30
-rwxr-xr-x1241/CH3/EX3.6/exa3_6.sce30
-rwxr-xr-x1241/CH3/EX3.7/exa3_7.sce29
-rwxr-xr-x1241/CH3/EX3.8/exa3_8.sce29
-rwxr-xr-x1241/CH3/EX3.9/exa3_9.sce60
11 files changed, 512 insertions, 0 deletions
diff --git a/1241/CH3/EX3.1/exa3_1.sce b/1241/CH3/EX3.1/exa3_1.sce
new file mode 100755
index 000000000..179edb64e
--- /dev/null
+++ b/1241/CH3/EX3.1/exa3_1.sce
@@ -0,0 +1,55 @@
+//Example 3-1//
+//BCD addition//
+clc
+//clears the console//
+clear
+//clears all existing variables//
+a=647
+b=492
+for i=1: 3
+ x(i)=modulo(a,10)
+ a=a/10
+ a=floor(a)
+ y(i)=modulo(b,10)
+ b=b/10
+ b=floor(b)
+end
+d=x(1)+y(1)
+db=dec2bin(d)
+if d>9 then
+ db=dec2bin(d+6)
+ db=dec2bin(bin2dec(db)-bin2dec('10000'))
+end
+e=x(2)+y(2)
+eb=dec2bin(e)
+if d>9 then
+ eb=dec2bin(e+1)
+ e=e+1
+ end
+if e>9
+ eb=dec2bin(e+6)
+ eb=dec2bin(bin2dec(eb)-bin2dec('10000'))
+end
+f=x(3)+y(3)
+fb=dec2bin(f)
+if e>9 then
+ fb=dec2bin(f+1)
+ f=f+1
+ end
+if f>9
+ fb=dec2bin(f+6)
+ fb=dec2bin(bin2dec(fb)-bin2dec('10000'))
+ dc(4)=1
+ end
+dc(1)=bin2dec(db)
+dc(2)=bin2dec(eb)
+dc(3)=bin2dec(fb)
+z=0
+for i=1: 4
+ z=z+dc(i)*(10^(i-1))
+end
+disp(z)
+disp('equivalent binary form')
+p=strcat(dec2bin(dc(4),1)+dec2bin(dc(3),4)+dec2bin(dc(2),4)+dec2bin(dc(1),4))
+disp(p)
+//answer is displayed//
diff --git a/1241/CH3/EX3.10/exa3_10.sce b/1241/CH3/EX3.10/exa3_10.sce
new file mode 100755
index 000000000..471e17db2
--- /dev/null
+++ b/1241/CH3/EX3.10/exa3_10.sce
@@ -0,0 +1,57 @@
+//Example 3-10//
+//Hamming code//
+clc
+//clears the command window//
+clear
+//clears all existing variables//
+z=0101
+//input//
+a=0;b=0;c=0;d=0;
+//taking the input//
+for i=1:7
+ x(i)=0
+ if i==3 then
+ x(i)=1
+ end
+ if i==6 then
+ x(i)=1
+ end
+end
+//establishing even parity at positions 1,3,5,7//
+for i=1: 7
+ if i==6 then
+ continue
+ end
+ if x(i)==1 then
+ a=a+1
+ end
+end
+d=modulo(a,2)
+if (d==1) then
+ x(1)=1
+end
+//establishing even parity at positions 2,3,6,7//
+for i=2: 7
+ if x(i)==1 then
+ b=b+1
+ end
+end
+d=modulo(b,2)
+if (d==1) then
+ x(2)=1
+end
+//establishing even parity at positions 4,5,6,7//
+for i=5:7
+ if (x(i)==1) then
+ c=c+1
+ end
+end
+d=modulo(c,2)
+if (d==1) then
+ x(4)=1
+end
+//displaying the result//
+disp('the hamming code for this data is given as')
+for i=1:7
+ disp(x(i))
+end
diff --git a/1241/CH3/EX3.11/exa3_11.sce b/1241/CH3/EX3.11/exa3_11.sce
new file mode 100755
index 000000000..36b146df4
--- /dev/null
+++ b/1241/CH3/EX3.11/exa3_11.sce
@@ -0,0 +1,76 @@
+//Example 3-11//
+//Correction of received Hamming code//
+clc
+//clears the console//
+clear
+//clears all existing variables//
+z=1111101
+//incorrect code taken as input//
+a=0;b=0;c=0;d=0;
+//taking the input in an array//
+for i=1: 7
+ x(i)=1
+ if i==2 then
+ x(i)=0
+ end
+end
+//checking for 4,5,6,7 even parity//
+for i=4: 7
+ if x(i)==1 then
+ a=a+1
+ end
+end
+d=modulo(a,2)
+if d==1 then
+ disp('wrong entry for 4,5,6,7')
+ x(4)=1
+else
+ disp('correct entry for 4,5,6,7')
+end
+//checking for 2,3,6,7 even parity//
+for i=2: 7
+ if i==4 then
+ continue
+ end
+ if i==5 then
+ continue
+ end
+ if x(i)==1 then
+ a=a+1
+ end
+end
+d=modulo(a,2)
+if d==1 then
+ disp('wrong entry for 2,3,6,7')
+ x(2)=1
+else
+ disp('correct entry for 2,3,6,7')
+end
+//checking for 1,3,5,7 even parity//
+for i=1: 7
+ if i==2 then
+ continue
+ end
+ if i==4 then
+ continue
+ end
+ if i==6 then
+ continue
+ end
+ if x(i)==1 then
+ a=a+1
+ end
+end
+d=modulo(a,2)
+if d==1 then
+ disp('correct entry for 1,3,5,7')
+ x(1)=1
+else
+ disp('wrong entry for 1,3,5,7')
+end
+disp('Therefore,bit 2 is in error and the corrected code is :')
+for i=1: 7
+ disp(x(i))
+end
+//correct code is displayed//
+
diff --git a/1241/CH3/EX3.2/exa3_2.sce b/1241/CH3/EX3.2/exa3_2.sce
new file mode 100755
index 000000000..2df1386b0
--- /dev/null
+++ b/1241/CH3/EX3.2/exa3_2.sce
@@ -0,0 +1,66 @@
+//Example 3-2//
+//BCD addition//
+clc
+//clears the console//
+clear
+//clears all existing variables//
+a=4318
+b=7678
+for i=1: 4
+ x(i)=modulo(a,10)
+ a=a/10
+ a=floor(a)
+ y(i)=modulo(b,10)
+ b=b/10
+ b=floor(b)
+end
+d=x(1)+y(1)
+db=dec2bin(d)
+if d>9 then
+ db=dec2bin(d+6)
+ db=dec2bin(bin2dec(db)-bin2dec('10000'))
+end
+e=x(2)+y(2)
+eb=dec2bin(e)
+if d>9 then
+ eb=dec2bin(e+1)
+ e=e+1
+ end
+if e>9
+ eb=dec2bin(e+6)
+ eb=dec2bin(bin2dec(eb)-bin2dec('10000'))
+end
+f=x(3)+y(3)
+fb=dec2bin(f)
+if e>9 then
+ fb=dec2bin(f+1)
+ f=f+1
+ end
+if f>9
+ fb=dec2bin(f+6)
+ fb=dec2bin(bin2dec(fb)-bin2dec('10000'))
+end
+g=x(4)+y(4)
+gb=dec2bin(g)
+if f>9 then
+ gb=dec2bin(g+1)
+ g=g+1
+ end
+if g>9
+ gb=dec2bin(g+6)
+ gb=dec2bin(bin2dec(gb)-bin2dec('10000'))
+ dc(5)=1
+end
+dc(1)=bin2dec(db)
+dc(2)=bin2dec(eb)
+dc(3)=bin2dec(fb)
+dc(4)=bin2dec(gb)
+z=0
+for i=1: 5
+ z=z+dc(i)*(10^(i-1))
+end
+disp(z)
+disp('equivalent binary form')
+p=strcat(dec2bin(dc(5),1)+dec2bin(dc(4),4)+dec2bin(dc(3),4)+dec2bin(dc(2),4)+dec2bin(dc(1),4))
+disp(p)
+//answer is displayed//
diff --git a/1241/CH3/EX3.3/exa3_3.sce b/1241/CH3/EX3.3/exa3_3.sce
new file mode 100755
index 000000000..9feb4c56c
--- /dev/null
+++ b/1241/CH3/EX3.3/exa3_3.sce
@@ -0,0 +1,40 @@
+//Example 3-3//
+//add 3 and 2 in Excess 3 code//
+clc
+//clears the console//
+clear
+//clears all existing variables//
+n=3
+m=2
+z=0
+a=0110
+b=0101
+ea=dec2bin(n+3)
+eb=dec2bin(m+3)
+for i=1: 4
+ x(i)=modulo(a,10)
+ a=a/10
+ a=floor(a)
+ y(i)=modulo(b,10)
+ b=b/10
+ b=floor(b)
+end
+for i=1: 4
+ g(i)=bitand(x(i),y(i))
+ p(i)=bitor(x(i),y(i))
+end
+c(1)=0
+for i=1: 4
+ c(i+1)=bitor(g(i),bitand(p(i),c(i)))
+end
+if c(5)==1 then
+ z=dec2bin(bin2dec(ea)+bin2dec(eb)+3)
+end
+if c(5)==0 then
+ z=dec2bin(bin2dec(ea)+bin2dec(eb)-3)
+end
+disp('equivalent binary number after excess 3 addition' )
+disp(z)
+disp('equivalent decimal number')
+disp(m+n)
+//result is displayed//
diff --git a/1241/CH3/EX3.4/exa3_4.sce b/1241/CH3/EX3.4/exa3_4.sce
new file mode 100755
index 000000000..a096d18b4
--- /dev/null
+++ b/1241/CH3/EX3.4/exa3_4.sce
@@ -0,0 +1,40 @@
+//Example 3-4//
+//add 6 and 8 in Excess 3 code//
+clc
+//clears the console//
+clear
+//clears all existing variables//
+n=6
+m=8
+a=1001
+b=1011
+ea=dec2bin(n+3)
+eb=dec2bin(m+3)
+for i=1: 4
+ x(i)=modulo(a,10)
+ a=a/10
+ a=floor(a)
+ y(i)=modulo(b,10)
+ b=b/10
+ b=floor(b)
+end
+for i=1: 4
+ g(i)=bitand(x(i),y(i))
+ p(i)=bitor(x(i),y(i))
+end
+c(1)=0
+for i=1: 4
+ c(i+1)=bitor(g(i),bitand(p(i),c(i)))
+end
+if c(5)==1 then
+ z=dec2bin(bin2dec(ea)+bin2dec(eb)+3)
+end
+if c(5)==0 then
+ z=dec2bin(bin2dec(ea)+bin2dec(eb)-3)
+end
+disp('equivalent binary number after excess 3 addition' )
+disp(z)
+disp('equivalent decimal number')
+disp(m+n)
+//result is displayed//
+
diff --git a/1241/CH3/EX3.5/exa3_5.sce b/1241/CH3/EX3.5/exa3_5.sce
new file mode 100755
index 000000000..072664120
--- /dev/null
+++ b/1241/CH3/EX3.5/exa3_5.sce
@@ -0,0 +1,30 @@
+//Example 3-5//
+//binary to gray code//
+clc
+//clears the console//
+clear
+//clears all existing variables//
+a=1011
+for i=1: 4
+ x(i)=modulo(a,10)
+ a=a/10
+ a=floor(a)
+end
+y(4)=x(4)
+k=3
+while(k>0)
+ if bitand(x(k+1),x(k))==1 then
+ y(k)=bitcmp(1,1)
+ else
+ y(k)=bitor(x(k+1),x(k))
+ end
+ k=k-1
+end
+//display//
+z=0
+for i=1: 4
+ z=z+y(i)*(10^(i-1))
+end
+disp('equivalent gray code')
+disp(z)
+//equivalent gray code is displayed//
diff --git a/1241/CH3/EX3.6/exa3_6.sce b/1241/CH3/EX3.6/exa3_6.sce
new file mode 100755
index 000000000..71d0da64b
--- /dev/null
+++ b/1241/CH3/EX3.6/exa3_6.sce
@@ -0,0 +1,30 @@
+//Example 3-6//
+//binary to gray code//
+clc
+//clears the console//
+clear
+//clears all existing variables//
+a=1001011
+for i=1: 7
+ x(i)=modulo(a,10)
+ a=a/10
+ a=floor(a)
+end
+y(7)=x(7)
+k=6
+while(k>0)
+ if bitand(x(k+1),x(k))==1 then
+ y(k)=bitcmp(1,1)
+ else
+ y(k)=bitor(x(k+1),x(k))
+ end
+ k=k-1
+end
+//display//
+z=0
+for i=1: 7
+ z=z+y(i)*(10^(i-1))
+end
+disp('equivalent gray code')
+disp(z)
+//equivalent gray code is displayed//
diff --git a/1241/CH3/EX3.7/exa3_7.sce b/1241/CH3/EX3.7/exa3_7.sce
new file mode 100755
index 000000000..046fd2923
--- /dev/null
+++ b/1241/CH3/EX3.7/exa3_7.sce
@@ -0,0 +1,29 @@
+//Example 3-7//
+//gray code to binary//
+clc
+//clears the console//
+clear
+//clears all existing variables//
+a=1011
+for i=1: 4
+ x(i)=modulo(a,10)
+ a=a/10
+ a=floor(a)
+end
+y(4)=x(4)
+k=3
+while(k>0)
+ if bitand(y(k+1),x(k))==1 then
+ y(k)=bitcmp(1,1)
+ else
+ y(k)=bitor(y(k+1),x(k))
+ end
+ k=k-1
+end
+z=0
+for i=1: 4
+ z=z+y(i)*(10^(i-1))
+end
+disp('equivalent binary code')
+disp(z)
+//equivalent binary code is displayed//
diff --git a/1241/CH3/EX3.8/exa3_8.sce b/1241/CH3/EX3.8/exa3_8.sce
new file mode 100755
index 000000000..bb96bd423
--- /dev/null
+++ b/1241/CH3/EX3.8/exa3_8.sce
@@ -0,0 +1,29 @@
+//Example 3-8//
+//gray code to binary//
+clc
+//clears the console//
+clear
+//clears all existing variables//
+a=1001011
+for i=1: 7
+ x(i)=modulo(a,10)
+ a=a/10
+ a=floor(a)
+end
+y(7)=x(7)
+k=6
+while(k>0)
+ if bitand(y(k+1),x(k))==1 then
+ y(k)=bitcmp(1,1)
+ else
+ y(k)=bitor(y(k+1),x(k))
+ end
+ k=k-1
+end
+z=0
+for i=1: 7
+ z=z+y(i)*(10^(i-1))
+end
+disp('equivalent binary code:')
+disp(z)
+//equivalent binary code is displayed//
diff --git a/1241/CH3/EX3.9/exa3_9.sce b/1241/CH3/EX3.9/exa3_9.sce
new file mode 100755
index 000000000..d852255cd
--- /dev/null
+++ b/1241/CH3/EX3.9/exa3_9.sce
@@ -0,0 +1,60 @@
+//Example 3-9//
+//Hamming code//
+clc
+//clears the command window//
+clear
+//clears all existing variables//
+z=1011
+//input//
+a=0;b=0;c=0;d=0;
+//taking the input//
+for i=1:7
+ x(i)=0
+ if i==3 then
+ x(i)=1
+ end
+ if i==5 then
+ x(i)=1
+ end
+ if i==7 then
+ x(i)=1
+ end
+end
+//establishing even parity at positions 1,3,5,7//
+for i=1: 7
+ if x(i)==1 then
+ a=a+1
+ end
+end
+d=modulo(a,2)
+if (d==1) then
+ x(1)=1
+end
+//establishing even parity at positions 2,3,6,7//
+for i=2: 7
+ if (i==5) then
+ continue
+ end
+ if (x(i)==1) then
+ b=b+1
+ end
+end
+d=modulo(b,2)
+if (d==1) then
+ x(2)=1
+end
+//establishing even parity at positions 4,5,6,7//
+for i=5:7
+ if (x(i)==1) then
+ c=c+1
+ end
+end
+d=modulo(c,2)
+if (d==1) then
+ x(4)=1
+end
+//displaying the result//
+disp('the hamming code for this data is given as')
+for i=1:7
+ disp(x(i))
+end