diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /275/CH8 | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '275/CH8')
24 files changed, 1283 insertions, 0 deletions
diff --git a/275/CH8/EX8.8.10/Ch8_8_10.sce b/275/CH8/EX8.8.10/Ch8_8_10.sce new file mode 100755 index 000000000..60a996532 --- /dev/null +++ b/275/CH8/EX8.8.10/Ch8_8_10.sce @@ -0,0 +1,46 @@ +clc
+clear
+disp("Example 8.10")
+printf("\n")
+disp("convert the following decimal to binary numbers")
+disp("a)47.8125 b)100.0001 c)29.3749")
+//given decimal number
+i=1;x=1
+dec=47.8125
+//separating integer part
+IP=floor(dec)
+IP1=IP
+//separating decimal part
+DP=modulo(dec,1)
+//storing each integer digit in I(i)
+while(IP>0)
+ I(i)=(modulo(floor(IP),2))
+ IP=floor(IP)/2
+ i=i+1
+end
+if(IP1>0)
+IP=0
+for j=1:length(I)
+//multipliying bits of integer part with their position values and adding
+ IP=IP+(I(j)*10^(j-1));
+ end
+else
+ IP=0
+end
+
+//storing each decimal digit in D(x)
+while(x<=4)
+ DP=DP*2
+ D(x)=floor(DP)
+ x=x+1
+ DP=modulo(DP,1)
+end
+
+DP=0
+for j=1:length(D)
+//multipliying bits of decimal part with their position values and adding
+ DP=DP+(10^(-1*j)*D(j))
+end
+Binary=IP+DP;
+printf("Binary format is")
+disp(Binary)
diff --git a/275/CH8/EX8.8.12/Ch8_8_12.sce b/275/CH8/EX8.8.12/Ch8_8_12.sce new file mode 100755 index 000000000..9f104d1d8 --- /dev/null +++ b/275/CH8/EX8.8.12/Ch8_8_12.sce @@ -0,0 +1,79 @@ +clc
+clear
+disp("Example 8.12")
+printf("\n")
+disp("convert the following octal to decimal")
+disp("a)243 b)124.21 c)0.65")
+//Given octal number
+i=1;w=1
+oct=243
+//separating integer part
+IP=floor(oct)
+IP1=IP
+//separating decimal part
+DP=modulo(oct,1)
+DP1=DP
+//converting decimal value to interger
+p=2
+DP=DP*10^p //should change power of 10 as according to number of digits in decimal digit
+//storing each integer digit in I(i)
+while(IP>0)
+ I(i)=modulo(IP,10);
+ IP=floor(IP/10);
+ i=i+1;
+ end
+//storing each decimal digit in D(w)
+while(DP>0)
+ D(w)=modulo(DP,10)
+ DP=(DP/10)
+ DP=floor(DP)
+ w=w+1;
+ end
+//to do zero padding of remaining erm of D(w)
+if(DP1<1)
+ if(DP1>0)
+if(length(D)<p)
+ q=length(D)
+ for f=q+1 :p
+ D(f)=0
+ end
+ end
+end
+end
+
+if(IP1>0)
+for i=1:length(I)//checking whether it is a octal number or not
+ if(I(i)>8) then
+ disp('not a octal number')
+ abort
+ end
+ end
+end
+if(IP1>0)
+IP=0
+for i=1:length(I)
+//multipliying bits of integer part with their position values and adding
+ IP=IP+(I(i)*8^(i-1))
+ end
+end
+
+if(DP1<1)
+ if(DP1>0)
+DP=0
+for z=1:length(D)
+ //multipliying bits of decimal part with their position values and adding
+ if(D(z)<8)
+ DP=DP+(D(z)*8^(-1*(length(D)+1-z)))
+ else
+ IP=0
+ DP=0
+ printf("not a octal number")
+ abort
+ end
+end
+end
+
+decimal=IP+DP
+//displaying the output
+printf("Decimal format")
+disp(decimal)
diff --git a/275/CH8/EX8.8.13/Ch8_8_13.sce b/275/CH8/EX8.8.13/Ch8_8_13.sce new file mode 100755 index 000000000..0c2c8e947 --- /dev/null +++ b/275/CH8/EX8.8.13/Ch8_8_13.sce @@ -0,0 +1,50 @@ +clc
+clear
+disp("Example 8.13")
+printf("\n")
+disp("convert the following decimael numbers to Octal")
+disp("a)283 b)847.951 c)0.728")
+//given decimal number
+i=1;x=1
+dec=283
+//separating integer part
+IP=floor(dec)
+IP1=IP
+//separating decimal part
+DP=modulo(dec,1)
+//storing each integer digit in I(i)
+while(IP>0)
+ I(i)=(modulo(floor(IP),8))
+ IP=floor(IP)/8
+ i=i+1
+end
+if(IP1>0)
+IP=0
+for j=1:length(I)
+//multipliying bits of integer part with their position values and adding
+ IP=IP+(I(j)*10^(j-1));
+ end
+else
+ IP=0
+end
+
+//storing each decimal digit in D(x)
+if(DP<1)
+ if(DP>0)
+while(x<=4)
+ DP=DP*8
+ D(x)=floor(DP)
+ x=x+1
+ DP=modulo(DP,1)
+end
+
+DP=0
+for j=1:length(D)
+//multipliying bits of decimal part with their position values and adding
+ DP=DP+(10^(-1*j)*D(j))
+ end
+end
+end
+octal=IP+DP
+printf("Octal format")
+disp(octal)
diff --git a/275/CH8/EX8.8.14/Ch8_8_14.sce b/275/CH8/EX8.8.14/Ch8_8_14.sce new file mode 100755 index 000000000..f2282224a --- /dev/null +++ b/275/CH8/EX8.8.14/Ch8_8_14.sce @@ -0,0 +1,119 @@ +clc
+clear
+disp("Example 8.14")
+printf("\n")
+disp("convert the following binary number to Octal")
+disp("a)101111 b)1010101 c)1110.01101")
+i=1;x=1;w=1
+//convert binary to decimal
+bin=101111
+//separating integer part
+IP=floor(bin)
+IP1=IP
+//separating decimal part
+DP=modulo(bin,1)
+DP1=DP
+//converting decimal value to interger
+p=5
+DP=DP*10^p //should change power of 10 as according to number of digits in decimal digit
+//storing each integer digit in I(i)
+while(IP>0)
+ I(i)=modulo(IP,10);
+ IP=floor(IP/10);
+ i=i+1;
+ end
+//storing each decimal digit in D(w)
+while(DP>0)
+ D(w)=modulo(DP,2)
+ DP=(DP/10)
+ DP=floor(DP)
+ w=w+1;
+ end
+ //to do zero padding of remaining erm of D(w)
+ if(DP1>0)
+ if(DP1<1)
+if(length(D)<p)
+ q=length(D)
+ for f=q+1 :p
+ D(f)=0
+ end
+ end
+end
+end
+if(IP1>0)
+for i=1:length(I)//checking whether it is a binary number or not
+ if(I(i)>1) then
+ disp('not a binary number')
+ abort
+ end
+ end
+end
+if(IP1>0)
+IP=0
+for i=1:length(I)
+//multipliying bits of integer part with their position values and adding
+ IP=IP+(I(i)*2^(i-1))
+ end
+end
+if(DP1>0)
+ if(DP1<1)
+DP=0
+for z=1:length(D)
+//multipliying bits of decimal part with their position values and adding
+ DP=DP+(D(z)*2^(-1*(length(D)+1-z)))
+ end
+ else
+ DP=0
+end
+else
+DP=0
+end
+decimal=IP+DP
+//displaying the output
+disp(decimal)
+
+
+
+//convert decimal to octal
+i=1;
+//separating integer part
+IP2=floor(decimal)
+IP3=IP2
+//separating decimal part
+DP2=modulo(decimal,1)
+//storing each integer digit in I(i)
+while(IP2>0)
+ J(i)=(modulo(floor(IP2),8))
+ IP2=floor(IP2)/8
+ i=i+1
+end
+if(IP3>0)
+IP2=0
+for j=1:length(J)
+//multipliying bits of integer part with their position values and adding
+ IP2=IP2+(J(j)*10^(j-1));
+ end
+else
+ IP2=0
+end
+
+//storing each decimal digit in D(x)
+if(DP2<1)
+ if(DP2>0)
+while(x<=4)
+ DP2=DP2*8
+ E(x)=floor(DP2)
+ x=x+1
+ DP2=modulo(DP2,1)
+end
+
+DP2=0
+for j=1:length(E)
+//multipliying bits of decimal part with their position values and adding
+ DP2=DP2+(10^(-1*j)*E(j))
+ end
+end
+end
+octal=IP2+DP2
+printf("Octal format")
+disp(octal)
diff --git a/275/CH8/EX8.8.15/Ch8_8_15.sce b/275/CH8/EX8.8.15/Ch8_8_15.sce new file mode 100755 index 000000000..fc411fdf8 --- /dev/null +++ b/275/CH8/EX8.8.15/Ch8_8_15.sce @@ -0,0 +1,121 @@ +clc
+clear
+disp("Example 8.15")
+printf("\n")
+disp("convert the following octal to binary number")
+disp("a)724 b)365.217 c)0.506")
+//Given binary number
+i=1;w=1
+bin=724
+//separating integer part
+IP=floor(bin)
+IP1=IP
+//separating decimal part
+DP=modulo(bin,1)
+DP1=DP
+//converting decimal value to interger
+p=2
+DP=DP*10^p //should change power of 10 as according to number of digits in decimal digit
+//storing each integer digit in I(i)
+while(IP>0)
+ I(i)=modulo(IP,10);
+ IP=floor(IP/10);
+ i=i+1;
+ end
+//storing each decimal digit in D(w)
+while(DP>0)
+ D(w)=modulo(DP,10)
+ DP=(DP/10)
+ DP=floor(DP)
+ w=w+1;
+ end
+//to do zero padding of remaining erm of D(w)
+if(DP1<1)
+ if(DP1>0)
+if(length(D)<p)
+ q=length(D)
+ for f=q+1 :p
+ D(f)=0
+ end
+ end
+end
+end
+
+if(IP1>0)
+for i=1:length(I)//checking whether it is a octal number or not
+ if(I(i)>8) then
+ disp('not a octal number')
+ abort
+ end
+ end
+end
+if(IP1>0)
+IP=0
+for i=1:length(I)
+//multipliying bits of integer part with their position values and adding
+ IP=IP+(I(i)*8^(i-1))
+ end
+end
+
+if(DP1<1)
+ if(DP1>0)
+DP=0
+for z=1:length(D)
+ //multipliying bits of decimal part with their position values and adding
+ if(D(z)<8)
+ DP=DP+(D(z)*8^(-1*(length(D)+1-z)))
+ else
+ IP=0
+ DP=0
+ printf("not a octal number")
+ abort
+ end
+end
+end
+
+decimal=IP+DP
+//displaying the output
+disp(decimal)
+
+
+
+//decimal to Binary
+//given decimal number
+i=1;x=1
+//separating integer part
+IP2=floor(decimal)
+IP3=IP2
+//separating decimal part
+DP2=modulo(decimal,1)
+//storing each integer digit in I(i)
+while(IP2>0)
+ J(i)=(modulo(floor(IP2),2))
+ IP2=floor(IP2)/2
+ i=i+1
+end
+if(IP3>0)
+IP2=0
+for j=1:length(J)
+//multipliying bits of integer part with their position values and adding
+ IP2=IP2+(J(j)*10^(j-1));
+ end
+else
+ IP2=0
+end
+
+//storing each decimal digit in D(x)
+while(x<=4)
+ DP2=DP2*2
+ E(x)=floor(DP)
+ x=x+1
+ DP2=modulo(DP2,1)
+end
+
+DP2=0
+for j=1:length(E)
+//multipliying bits of decimal part with their position values and adding
+ DP2=DP2+(10^(-1*j)*E(j))
+end
+Binary=IP2+DP2;
+printf("Binary format")
+disp(Binary)
diff --git a/275/CH8/EX8.8.17/Ch8_8_17.sce b/275/CH8/EX8.8.17/Ch8_8_17.sce new file mode 100755 index 000000000..a55db7156 --- /dev/null +++ b/275/CH8/EX8.8.17/Ch8_8_17.sce @@ -0,0 +1,10 @@ +clc
+clear
+disp("Example 8.17")
+printf("\n")
+disp("convert the following hexadecimael numbers to decimal")
+disp("a)FACE b)31C c)CAD")
+//this progra, converts only integer part to decimal
+Hdec='FACE'
+dec=hex2dec(Hdec);
+printf("decimal=%d",dec)
\ No newline at end of file diff --git a/275/CH8/EX8.8.18/Ch8_8_18.sce b/275/CH8/EX8.8.18/Ch8_8_18.sce new file mode 100755 index 000000000..79b824143 --- /dev/null +++ b/275/CH8/EX8.8.18/Ch8_8_18.sce @@ -0,0 +1,10 @@ +clc
+clear
+disp("Example 8.17")
+printf("\n")
+disp("convert the following decimael numbers to hexadecimal")
+disp("a)2146 b)843 c)2604")
+//this program, converts only integer part to hexadecimal
+dec=843
+Hdec=dec2hex(dec);
+printf("decimal=%s",Hdec)
diff --git a/275/CH8/EX8.8.19/Ch8_8_19.sce b/275/CH8/EX8.8.19/Ch8_8_19.sce new file mode 100755 index 000000000..8ff17ea54 --- /dev/null +++ b/275/CH8/EX8.8.19/Ch8_8_19.sce @@ -0,0 +1,11 @@ +clc
+clear
+disp("Example 8.19")
+printf("\n")
+disp("convert the following binary numbers to hexadecimal")
+disp("a)101110 b)11010 c)1011101")
+//this program, converts only integer part to decimal
+bin='101110'
+dec=bin2dec(bin)
+Hdec=dec2hex(dec)
+printf("decimal=%s",Hdec)
diff --git a/275/CH8/EX8.8.21/Ch8_8_21.sce b/275/CH8/EX8.8.21/Ch8_8_21.sce new file mode 100755 index 000000000..53a3b7837 --- /dev/null +++ b/275/CH8/EX8.8.21/Ch8_8_21.sce @@ -0,0 +1,182 @@ +kclc
+clear
+disp("Example 8.21")
+printf("\n")
+disp("Add the following binary numbers")
+disp("a)11011 & 10110 b)1100 & 111 c)10.1011 & 11.011")
+//Given binary number
+i=1;w=1
+a=11011
+b=10110
+//Given binary number
+i=1;w=1
+bin=11.101
+//separating integer part
+IPa=floor(a)
+IP1a=IPa
+//separating decimal part
+DPa=modulo(a,1)
+DP1a=DPa
+//converting decimal value to interger
+p=4
+DPa=DPa*10^p //should change power of 10 as according to number of digits in decimal digit
+
+//storing each integer digit in I(i)
+while(IPa>0)
+ Ia(i)=modulo(IPa,10);
+ IPa=floor(IPa/10);
+ i=i+1;
+ end
+//storing each decimal digit in D(w)
+while(DPa>0)
+ Da(w)=modulo(DPa,2)
+ DPa=(DPa/10)
+ DPa=floor(DPa)
+ w=w+1;
+ end
+ //to do zero padding of remaining erm of D(w)
+ if(DP1a<1)
+ if(DP1a>0)
+if(length(Da)<p)
+ q=length(Da)
+ for f=q+1 :p
+ Da(f)=0
+ end
+ end
+end
+end
+
+if(IP1a>0)
+for i=1:length(Ia)//checking whether it is a binary number or not
+ if(Ia(i)>1) then
+ disp('not a binary number')
+ abort
+ end
+ end
+end
+if(IP1a>0)
+IPa=0
+for i=1:length(Ia)
+//multipliying bits of integer part with their position values and adding
+ IPa=IPa+(Ia(i)*2^(i-1))
+ end
+ end
+ DPa=0
+ if(DP1a>0)
+ if(DP1a<1)
+for z=1:length(Da)
+//multipliying bits of decimal part with their position values and adding
+ DPa=DPa+(Da(z)*2^(-1*(length(Da)+1-z)))
+ end
+end
+end
+decimala=IPa+DPa
+//displaying the output
+disp(decimala)
+
+//for b
+//Given binary number
+i=1;w=1
+//separating integer part
+IPb=floor(b)
+IP1b=IPb
+//separating decimal part
+DPb=modulo(b,1)
+DP1b=DPb
+//converting decimal value to interger
+p=3
+DPb=DPb*10^p //should change power of 10 as according to number of digits in decimal digit
+
+//storing each integer digit in I(i)
+while(IPb>0)
+ Ib(i)=modulo(IPb,10);
+ IPb=floor(IPb/10);
+ i=i+1;
+ end
+//storing each decimal digit in D(w)
+while(DPb>0)
+ Db(w)=modulo(DPb,2)
+ DPb=(DPb/10)
+ DPb=floor(DPb)
+ w=w+1;
+ end
+ //to do zero padding of remaining erm of D(w)
+ if(DP1b>0)
+ if(DP1b<1)
+if(length(Db)<p)
+ q=length(Db)
+ for f=q+1 :p
+ Db(f)=0
+ end
+ end
+end
+end
+if(IP1b>0)
+for i=1:length(Ib)//checking whether it is a binary number or not
+ if(Ib(i)>1) then
+ disp('not a binary number')
+ abort
+ end
+ end
+end
+if(IP1b>0)
+IPb=0
+for i=1:length(Ib)
+//multipliying bits of integer part with their position values and adding
+ IPb=IPb+(Ib(i)*2^(i-1))
+ end
+ end
+DPb=0
+if(DP1b>0)
+ if(DP1b<1)
+ for z=1:length(Db)
+//multipliying bits of decimal part with their position values and adding
+ DPb=DPb+(Db(z)*2^(-1*(length(Db)+1-z)))
+ end
+end
+end
+decimalb=IPb+DPb
+//displaying the output
+disp(decimalb)
+
+sum1=decimala+decimalb
+i=1;x=1
+
+//separating integer part
+IP=floor(sum1)
+IP1=IP
+//separating decimal part
+DP=modulo(sum1,1)
+//storing each integer digit in I(i)
+while(IP>0)
+ I(i)=(modulo(floor(IP),2))
+ IP=floor(IP)/2
+ i=i+1
+end
+if(IP1>0)
+IP=0
+for j=1:length(I)
+//multipliying bits of integer part with their position values and adding
+ IP=IP+(I(j)*10^(j-1));
+ end
+else
+ IP=0
+end
+
+//storing each decimal digit in D(x)
+while(x<=4)
+ DP=DP*2
+ D(x)=floor(DP)
+ x=x+1
+ DP=modulo(DP,1)
+end
+
+DP=0
+for j=1:length(D)
+//multipliying bits of decimal part with their position values and adding
+ DP=DP+(10^(-1*j)*D(j))
+end
+Binary=IP+DP;
+printf("Sum")
+disp(Binary)
+
diff --git a/275/CH8/EX8.8.23/Ch8_8_23.sce b/275/CH8/EX8.8.23/Ch8_8_23.sce new file mode 100755 index 000000000..83f61d32c --- /dev/null +++ b/275/CH8/EX8.8.23/Ch8_8_23.sce @@ -0,0 +1,196 @@ +clc
+clear
+disp("Example 8.23")
+printf("\n")
+disp("Add the following octal numbers")
+disp("a)46 & 375 b)27.34 & 11.76")
+//Given octal number
+i=1;w=1
+a=46
+b=375
+//separating integer part
+IPa=floor(a)
+IP1a=IPa
+//separating decimal part
+DPa=modulo(a,1)
+DP1a=DPa
+//converting decimal value to interger
+p=2
+DPa=DPa*10^p //should change power of 10 as according to number of digits in decimal digit
+//storing each integer digit in I(i)
+while(IPa>0)
+ Ia(i)=modulo(IPa,10);
+ IPa=floor(IPa/10);
+ i=i+1;
+ end
+//storing each decimal digit in D(w)
+while(DPa>0)
+ Da(w)=modulo(DPa,10)
+ DPa=(DPa/10)
+ DPa=floor(DPa)
+ w=w+1;
+ end
+//to do zero padding of remaining erm of D(w)
+if(DP1a<1)
+ if(DP1a>0)
+if(length(Da)<p)
+ q=length(Da)
+ for f=q+1 :p
+ Da(f)=0
+ end
+ end
+end
+end
+
+if(IP1a>0)
+for i=1:length(Ia)//checking whether it is a octal number or not
+ if(Ia(i)>8) then
+ disp('not a octal number')
+ abort
+ end
+ end
+end
+if(IP1a>0)
+IPa=0
+for i=1:length(Ia)
+//multipliying bits of integer part with their position values and adding
+ IPa=IPa+(Ia(i)*8^(i-1))
+ end
+end
+
+if(DP1a<1)
+ if(DP1a>0)
+DPa=0
+for z=1:length(Da)
+ //multipliying bits of decimal part with their position values and adding
+ if(Da(z)<8)
+ DPa=DPa+(Da(z)*8^(-1*(length(Da)+1-z)))
+ else
+ IPa=0
+ DPa=0
+ printf("not a octal number")
+ abort
+ end
+end
+end
+
+decimala=IPa+DPa
+//displaying the output
+disp(decimala)
+
+//for b
+//Given octal number
+i=1;w=1
+//separating integer part
+IPb=floor(b)
+IP1b=IPb
+//separating decimal part
+DPb=modulo(b,1)
+DP1b=DPb
+//converting decimal value to interger
+p=2
+DPb=DPb*10^p //should change power of 10 as according to number of digits in decimal digit
+//storing each integer digit in I(i)
+while(IPb>0)
+ Ib(i)=modulo(IPb,10);
+ IPb=floor(IPb/10);
+ i=i+1;
+ end
+//storing each decimal digit in D(w)
+while(DPb>0)
+ Db(w)=modulo(DPb,10)
+ DPb=(DPb/10)
+ DPb=floor(DPb)
+ w=w+1;
+ end
+//to do zero padding of remaining erm of D(w)
+if(DP1b<1)
+ if(DP1b>0)
+if(length(Db)<p)
+ q=length(Db)
+ for f=q+1 :p
+ Db(f)=0
+ end
+ end
+end
+end
+
+if(IP1b>0)
+for i=1:length(Ib)//checking whether it is a octal number or not
+ if(Ib(i)>8) then
+ disp('not a octal number')
+ abort
+ end
+ end
+end
+if(IP1b>0)
+IPb=0
+for i=1:length(Ib)
+//multipliying bits of integer part with their position values and adding
+ IPb=IPb+(Ib(i)*8^(i-1))
+ end
+end
+
+if(DP1b<1)
+ if(DP1b>0)
+DPb=0
+for z=1:length(Db)
+ //multipliying bits of decimal part with their position values and adding
+ if(Db(z)<8)
+ DPb=DPb+(Db(z)*8^(-1*(length(Db)+1-z)))
+ else
+ IPb=0
+ DPb=0
+ printf("not a octal number")
+ abort
+ end
+end
+end
+
+decimalb=IPb+DPb
+//displaying the output
+disp(decimalb)
+
+sum1=decimala+decimalb
+i=1;x=1
+//separating integer part
+IP=floor(sum1)
+IP1=IP
+//separating decimal part
+DP=modulo(sum1,1)
+//storing each integer digit in I(i)
+while(IP>0)
+ I(i)=(modulo(floor(IP),8))
+ IP=floor(IP)/8
+ i=i+1
+end
+if(IP1>0)
+IP=0
+for j=1:length(I)
+//multipliying bits of integer part with their position values and adding
+ IP=IP+(I(j)*10^(j-1));
+ end
+else
+ IP=0
+end
+
+//storing each decimal digit in D(x)
+if(DP<1)
+ if(DP>0)
+while(x<=4)
+ DP=DP*8
+ D(x)=floor(DP)
+ x=x+1
+ DP=modulo(DP,1)
+end
+
+DP=0
+for j=1:length(D)
+//multipliying bits of decimal part with their position values and adding
+ DP=DP+(10^(-1*j)*D(j))
+ end
+end
+end
+octal=IP+DP
+printf("Sum")
+disp(octal)
diff --git a/275/CH8/EX8.8.25/Ch8_8_25.sce b/275/CH8/EX8.8.25/Ch8_8_25.sce new file mode 100755 index 000000000..8f9a6edb0 --- /dev/null +++ b/275/CH8/EX8.8.25/Ch8_8_25.sce @@ -0,0 +1,14 @@ +clc
+clear
+disp("Example 8.25")
+printf("\n")
+disp("Add the following hexadecimal numbers")
+disp("a)ABC & ABCDE b) DEF & 12EF")
+//this program add only integer part
+a='ABC'
+b='ABCDE'
+a1=hex2dec(a)
+a2=hex2dec(b)
+sum1=a1+a2
+sumhex=dec2hex(sum1)
+printf("%s",sumhex)
\ No newline at end of file diff --git a/275/CH8/EX8.8.30a/Ch8_8_30a.sce b/275/CH8/EX8.8.30a/Ch8_8_30a.sce new file mode 100755 index 000000000..7c0c1dbb7 --- /dev/null +++ b/275/CH8/EX8.8.30a/Ch8_8_30a.sce @@ -0,0 +1,33 @@ +clc
+clear
+disp("Example 8.30a")
+printf("\n")
+disp("perform the following decimal subtraction using 9s complements")
+disp("a)49-24 b)321-578")
+//given numbers
+a=49
+b=-24
+//should set to 99 if input is 2 digit number,999 if 3digit number
+c=99
+//add c with 2nd operand
+e=c+b
+N=a+e
+if(N>100)
+ if(N<199)
+ M=N-100
+ M=M+1
+ N=M
+end
+end
+if(N>1000)
+ if(N<1999)
+ M=N-1000
+ M=M+1
+ N=M
+end
+end
+ M=N
+if(-b>a)
+ M=-(999-M)
+end
+printf("result=%d",M)
\ No newline at end of file diff --git a/275/CH8/EX8.8.30b/Ch8_8_30b.sce b/275/CH8/EX8.8.30b/Ch8_8_30b.sce new file mode 100755 index 000000000..73020d16a --- /dev/null +++ b/275/CH8/EX8.8.30b/Ch8_8_30b.sce @@ -0,0 +1,31 @@ +clc
+clear
+disp("Example 8.30b")
+printf("\n")
+disp("perform the following decimal subtraction using 10s complements")
+disp("a)49-24 b)321-578")
+//given numbers
+a=49
+b=-24
+//should set to 100 if input is 2 digit number,1000 if 3digit number
+c=1000
+//add c with 2nd operand
+e=c+b
+N=a+e
+if(N>100)
+ if(N<199)
+ M=N-100
+ N=M
+end
+end
+if(N>1000)
+ if(N<1999)
+ M=N-1000
+ N=M
+end
+end
+ M=N
+if(-b>a)
+ M=-(999-M+1)
+end
+printf("result=%d",M)
diff --git a/275/CH8/EX8.8.31a/Ch8_8_31a.sce b/275/CH8/EX8.8.31a/Ch8_8_31a.sce new file mode 100755 index 000000000..bc5abac67 --- /dev/null +++ b/275/CH8/EX8.8.31a/Ch8_8_31a.sce @@ -0,0 +1,43 @@ +clc
+clear
+disp("Example 8.31a")
+printf("\n")
+disp("perform the following binary substraction using 1s complement")
+disp("a)1010-0111 b)0110-1101")
+a=[1 0 1 0]
+b=~[0 1 1 1]
+d=0
+for i=1:length(a)
+ c(i)=a(length(a)+1-i)+b(length(a)+1-i)+d
+ if(c(i)==1)
+ d=0
+ end
+ if[c(i)==2]
+ d=1
+ c(i)=0
+ end
+end
+f=1
+if(d==1)
+ for i=1:length(a)
+ g(i)=c(i)+f
+ if(g(i)==1)
+ f=0
+ end
+ if(g(i)==2)
+ f=1
+ g(i)=0
+ end
+
+ end
+ for i=1:length(a)
+ c(i)=g(i)
+ end
+end
+if(d==0)
+ for i=1:length(a)
+ c(i)=~c(i)
+ end
+end
+printf("result =%d%d%d%d",c(4),c(3),c(2),c(1))
+
diff --git a/275/CH8/EX8.8.31b/Ch8_8_31b.sce b/275/CH8/EX8.8.31b/Ch8_8_31b.sce new file mode 100755 index 000000000..4cc46ef35 --- /dev/null +++ b/275/CH8/EX8.8.31b/Ch8_8_31b.sce @@ -0,0 +1,62 @@ +clc
+clear
+disp("Example 8.31b")
+printf("\n")
+disp("perform the following binary substraction using 2s complement")
+disp("a)1010-0111 b)0110-1101")
+a=[1 0 1 0]
+b=~[0 1 1 1]
+d=0
+h=1
+for i=1:length(b)
+ n(i)=b(length(b)+1-i)+h
+ if(n(i)==1)
+ h=0
+ end
+ if(n(i)==2)
+ h=1
+ n(i)=0
+ end
+
+ end
+ for i=1:length(a)
+ b(i)=n(i)
+ end
+
+
+for i=1:length(a)
+ c(i)=a(length(a)+1-i)+b(length(a)+1-i)+d
+ if(c(i)==1)
+ d=0
+ end
+ if[c(i)==2]
+ d=1
+ c(i)=0
+ end
+end
+
+
+if(d==0)
+ for i=1:length(a)
+ c(i)=~c(i)
+end
+j=1
+for i=1:length(b)
+ m(i)=c(i)+j
+ if(m(i)==1)
+ f=0
+ end
+ if(m(i)==2)
+ j=1
+ m(i)=0
+ end
+
+ end
+ for i=1:length(a)
+ c(i)=m(i)
+ end
+end
+for i=1:length(a)
+ C(i)=c(i)
+end
+printf("result =%d%d%d%d",c(4),c(3),c(2),c(1))
\ No newline at end of file diff --git a/275/CH8/EX8.8.48a/Ch8_8_48a.sce b/275/CH8/EX8.8.48a/Ch8_8_48a.sce new file mode 100755 index 000000000..a77924ce1 --- /dev/null +++ b/275/CH8/EX8.8.48a/Ch8_8_48a.sce @@ -0,0 +1,30 @@ +clc
+clear
+disp("Example 8.48a")
+printf("\n")
+disp("Prove the following boolean thereom")
+disp("A+AB=A")
+disp("A=a,B=b,AB=s,A+AB=d")
+a=[0 0 1 1]
+b=[0 1 0 1]
+for i=1:length(a)
+ s(i)=a(i)*b(i)
+end
+for i=1:length(a)
+ d(i)=s(i)+a(i)
+ if(d(i)==2)
+ d(i)=1
+ end
+
+end
+
+for i=1:length(a)
+ if(a(i)==d(i))
+ printf("")
+ else
+ printf("not")
+ abort
+ end
+
+end
+printf("yes")
\ No newline at end of file diff --git a/275/CH8/EX8.8.48b/Ch8_8_48b.sce b/275/CH8/EX8.8.48b/Ch8_8_48b.sce new file mode 100755 index 000000000..11a01cf43 --- /dev/null +++ b/275/CH8/EX8.8.48b/Ch8_8_48b.sce @@ -0,0 +1,37 @@ +clc
+clear
+disp("Example 8.48b")
+printf("\n")
+disp("Prove the following boolean thereom")
+disp("A+AB=A")
+disp("A=a,B=b,A1B=s,A+A1B=d")
+a=[0 0 1 1]
+b=[0 1 0 1]
+for i=1:length(a)
+ s(i)=(~a(i))*b(i)
+end
+for i=1:length(a)
+ d(i)=s(i)+a(i)
+ if(d(i)==2)
+ d(i)=1
+ end
+
+end
+
+for i=1:length(a)
+ e(i)=a(i)+b(i)
+ if(e(i)==2)
+ e(i)=1
+ end
+end
+
+for i=1:length(a)
+ if((e(i)==d(i)))
+ printf("_")
+ else
+ printf("not")
+ abort
+ end
+
+end
+printf("yes")
\ No newline at end of file diff --git a/275/CH8/EX8.8.49a/Ch8_8_49a.sce b/275/CH8/EX8.8.49a/Ch8_8_49a.sce new file mode 100755 index 000000000..95fe639c7 --- /dev/null +++ b/275/CH8/EX8.8.49a/Ch8_8_49a.sce @@ -0,0 +1,39 @@ +clc
+clear
+disp("Example 8.49a")
+printf("\n")
+disp("Prove the following boolean identities")
+disp("A+BC=(A+B)(A+C)")
+A=[0 0 0 0 1 1 1 1]
+B=[0 0 1 1 0 0 1 1]
+C=[0 1 0 1 0 1 0 1]
+for i=1:length(A)
+ Y(i)=A(i)+(B(i)*C(i))
+ if(Y(i)==2)
+ Y(i)=1
+ end
+end
+for i=1:length(A)
+ Z(i)=(A(i)+B(i))*(A(i)+C(i))
+ if(Z(i)==2)
+ Z(i)=1
+ end
+ if(Z(i)==3)
+ Z(i)=1
+ end
+ if(Z(i)==4)
+ Z(i)=1
+ end
+end
+for i=1:length(A)
+ if(Z(i)==Y(i))
+ printf("_")
+ else
+ printf("NOT")
+ abort
+ end
+end
+
+ printf("proved")
+
+
\ No newline at end of file diff --git a/275/CH8/EX8.8.49b/Ch8_8_49b.sce b/275/CH8/EX8.8.49b/Ch8_8_49b.sce new file mode 100755 index 000000000..3efa08162 --- /dev/null +++ b/275/CH8/EX8.8.49b/Ch8_8_49b.sce @@ -0,0 +1,33 @@ +clc
+clear
+disp("Example 8.49b")
+printf("\n")
+disp("Prove the following boolean identities")
+disp("ABC+AB1C+ABC1=AB+AC")
+A=[0 0 0 0 1 1 1 1]
+B=[0 0 1 1 0 0 1 1]
+C=[0 1 0 1 0 1 0 1]
+for i=1:length(A)
+ Y(i)=(A(i)*B(i)*C(i))+(A(i)*(~B(i))*C(i))+(A(i)*B(i)*(~C(i)))
+ if(Y(i)==3)
+ Y(i)=1
+ end
+ if(Y(i)==2)
+ Y(i)=1
+ end
+end
+for i=1:length(A)
+ Z(i)=(A(i)*B(i))+(A(i)*C(i))
+ if(Z(i)==2)
+ Z(i)=1
+ end
+end
+for i=1:length(A)
+ if(Z(i)==Y(i))
+ printf("_")
+ else
+ printf("NOT")
+ abort
+ end
+end
+ printf("proved")
diff --git a/275/CH8/EX8.8.50a/Ch8_8_50a.sce b/275/CH8/EX8.8.50a/Ch8_8_50a.sce new file mode 100755 index 000000000..f09a387fc --- /dev/null +++ b/275/CH8/EX8.8.50a/Ch8_8_50a.sce @@ -0,0 +1,16 @@ +clc
+clear
+disp("Example 8.50a")
+printf("\n")
+disp("Construct the Truth Table for logic expression")
+disp("AB1+C1")
+A=[0 0 0 0 1 1 1 1]
+B=[0 0 1 1 0 0 1 1]
+C=[0 1 0 1 0 1 0 1]
+for i=1:length(A)
+ f(i)=(A(i)*(~(B(i))))+(~C(i))
+ if(f(i)==2)
+ f(i)=1
+ end
+end
+printf("truth table =%d%d%d%d%d%d%d%d",f(1),f(2),f(3),f(4),f(5),f(6),f(7),f(8))
\ No newline at end of file diff --git a/275/CH8/EX8.8.50b/Ch8_8_50b.sce b/275/CH8/EX8.8.50b/Ch8_8_50b.sce new file mode 100755 index 000000000..e026d3dc1 --- /dev/null +++ b/275/CH8/EX8.8.50b/Ch8_8_50b.sce @@ -0,0 +1,15 @@ +clc
+clear
+disp("Example 8.50b")
+printf("\n")
+disp("Construct the Truth Table for logic expression")
+disp("AB1+A1B")
+A=[0 0 1 1]
+B=[0 1 0 1]
+for i=1:length(A)
+ f(i)=(A(i)*(~(B(i))))+(B(i)*(~(A(i))))
+ if(f(i)==2)
+ f(i)=1
+ end
+end
+printf("truth table =%d%d%d%d",f(1),f(2),f(3),f(4))
\ No newline at end of file diff --git a/275/CH8/EX8.8.50c/Ch8_8_50c.sce b/275/CH8/EX8.8.50c/Ch8_8_50c.sce new file mode 100755 index 000000000..7f1f8efac --- /dev/null +++ b/275/CH8/EX8.8.50c/Ch8_8_50c.sce @@ -0,0 +1,16 @@ +clc
+clear
+disp("Example 8.50c")
+printf("\n")
+disp("Construct the Truth Table for logic expression")
+disp("C1((B+D)1)")
+B=[0 0 0 0 1 1 1 1]
+C=[0 0 1 1 0 0 1 1]
+D=[0 1 0 1 0 1 0 1]
+for i=1:length(B)
+ f(i)=(~(C(i)))*(~(B(i)+D(i)))
+ if (f(i)==2)
+ f(i)=1
+ end
+end
+printf("truth table =%d%d%d%d%d%d%d%d",f(1),f(2),f(3),f(4),f(5),f(6),f(7),f(8))
\ No newline at end of file diff --git a/275/CH8/EX8.8.7/Ch8_8_7.sce b/275/CH8/EX8.8.7/Ch8_8_7.sce new file mode 100755 index 000000000..a9f2a9813 --- /dev/null +++ b/275/CH8/EX8.8.7/Ch8_8_7.sce @@ -0,0 +1,29 @@ +clc
+disp("Example 8.7")
+printf("\n")
+disp("convert the following binary numbers to decimal")
+disp("a)1011 b)110101 c)10101")
+//Given binary number
+bin=1011
+i=1
+//storing each integer digit in b(i)
+while(bin>0)
+ b(i)=modulo(bin,10)
+ bin=floor(bin/10)
+ i=i+1;
+end
+//checking whether it is a binary number or not
+for i=1:length(b)
+ if(b(i)>1) then
+ disp('not a binary number')
+ abort
+ end
+ end
+dec=0
+for i=1:length(b)
+//multipliying bits of integer part with their position values and adding
+ dec=dec+(b(i)*2^(i-1))
+end
+//displaying the output
+printf("decimal format is")
+disp(dec)
diff --git a/275/CH8/EX8.8.8/Ch8_8_8.sce b/275/CH8/EX8.8.8/Ch8_8_8.sce new file mode 100755 index 000000000..d8bfda1a3 --- /dev/null +++ b/275/CH8/EX8.8.8/Ch8_8_8.sce @@ -0,0 +1,61 @@ +clc
+clear
+disp("Example 8.8")
+printf("\n")
+disp("convert the following binary numbers to decimal")
+disp("a)11.101 b)0.0111 c)110.1101")
+//Given binary number
+i=1;w=1
+bin=11.101
+//separating integer part
+IP=floor(bin)
+IP1=IP
+//separating decimal part
+DP=modulo(bin,1)
+//converting decimal value to interger
+p=4
+DP=DP*10^p //should change power of 10 as according to number of digits in decimal digit
+//storing each integer digit in I(i)
+while(IP>0)
+ I(i)=modulo(IP,10);
+ IP=floor(IP/10);
+ i=i+1;
+ end
+//storing each decimal digit in D(w)
+while(DP>0)
+ D(w)=modulo(DP,2)
+ DP=(DP/10)
+ DP=floor(DP)
+ w=w+1;
+ end
+//to do zero padding of remaining erm of D(w)
+if(length(D)<p)
+ q=length(D)
+ for f=q+1 :p
+ D(f)=0
+ end
+end
+if(IP1>0)
+for i=1:length(I)//checking whether it is a binary number or not
+ if(I(i)>1) then
+ disp('not a binary number')
+ abort
+ end
+ end
+end
+if(IP1>0)
+IP=0
+for i=1:length(I)
+//multipliying bits of integer part with their position values and adding
+ IP=IP+(I(i)*2^(i-1))
+ end
+ end
+DP=0
+for z=1:length(D)
+//multipliying bits of decimal part with their position values and adding
+ DP=DP+(D(z)*2^(-1*(length(D)+1-z)))
+end
+decimal=IP+DP
+//displaying the output
+printf("Decimal format is")
+disp(decimal)
|