From b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b Mon Sep 17 00:00:00 2001 From: priyanka Date: Wed, 24 Jun 2015 15:03:17 +0530 Subject: initial commit / add all books --- 273/CH25/EX25.1/ex25_1.sce | 14 ++++++ 273/CH25/EX25.10/ex25_10.sce | 14 ++++++ 273/CH25/EX25.11/ex25_11.sce | 14 ++++++ 273/CH25/EX25.12/ex25_12.sce | 14 ++++++ 273/CH25/EX25.13/ex25_13.sce | 28 +++++++++++ 273/CH25/EX25.14/ex25_14.sce | 10 ++++ 273/CH25/EX25.15/ex25_15.sce | 10 ++++ 273/CH25/EX25.16/ex25_16.sce | 43 ++++++++++++++++ 273/CH25/EX25.17/ex25_17.sce | 39 +++++++++++++++ 273/CH25/EX25.18/ex25_18.sce | 11 ++++ 273/CH25/EX25.19/ex2519.sce | 81 ++++++++++++++++++++++++++++++ 273/CH25/EX25.2/ex25_2.sce | 13 +++++ 273/CH25/EX25.20/ex2520.sce | 75 ++++++++++++++++++++++++++++ 273/CH25/EX25.21/ex25_21.sce | 10 ++++ 273/CH25/EX25.22/ex2522.sce | 29 +++++++++++ 273/CH25/EX25.23/ex25_23.sce | 11 ++++ 273/CH25/EX25.24/ex25_24.sce | 11 ++++ 273/CH25/EX25.25/ex25_25.sce | 97 ++++++++++++++++++++++++++++++++++++ 273/CH25/EX25.26/ex25_26sce.sce | 88 ++++++++++++++++++++++++++++++++ 273/CH25/EX25.27/ex25_27sce.sce | 88 ++++++++++++++++++++++++++++++++ 273/CH25/EX25.28/ex25_28sce.sce | 35 +++++++++++++ 273/CH25/EX25.29/ex25_29.sce | 108 ++++++++++++++++++++++++++++++++++++++++ 273/CH25/EX25.3/ex25_3.sce | 13 +++++ 273/CH25/EX25.30/ex25_30.sce | 88 ++++++++++++++++++++++++++++++++ 273/CH25/EX25.4/ex25_4.sce | 14 ++++++ 273/CH25/EX25.5/ex25_5.sce | 14 ++++++ 273/CH25/EX25.6/ex25_6.sce | 14 ++++++ 273/CH25/EX25.7/ex25_7.sce | 14 ++++++ 273/CH25/EX25.8/ex25_8.sce | 14 ++++++ 273/CH25/EX25.9/ex25_9.sce | 14 ++++++ 30 files changed, 1028 insertions(+) create mode 100755 273/CH25/EX25.1/ex25_1.sce create mode 100755 273/CH25/EX25.10/ex25_10.sce create mode 100755 273/CH25/EX25.11/ex25_11.sce create mode 100755 273/CH25/EX25.12/ex25_12.sce create mode 100755 273/CH25/EX25.13/ex25_13.sce create mode 100755 273/CH25/EX25.14/ex25_14.sce create mode 100755 273/CH25/EX25.15/ex25_15.sce create mode 100755 273/CH25/EX25.16/ex25_16.sce create mode 100755 273/CH25/EX25.17/ex25_17.sce create mode 100755 273/CH25/EX25.18/ex25_18.sce create mode 100755 273/CH25/EX25.19/ex2519.sce create mode 100755 273/CH25/EX25.2/ex25_2.sce create mode 100755 273/CH25/EX25.20/ex2520.sce create mode 100755 273/CH25/EX25.21/ex25_21.sce create mode 100755 273/CH25/EX25.22/ex2522.sce create mode 100755 273/CH25/EX25.23/ex25_23.sce create mode 100755 273/CH25/EX25.24/ex25_24.sce create mode 100755 273/CH25/EX25.25/ex25_25.sce create mode 100755 273/CH25/EX25.26/ex25_26sce.sce create mode 100755 273/CH25/EX25.27/ex25_27sce.sce create mode 100755 273/CH25/EX25.28/ex25_28sce.sce create mode 100755 273/CH25/EX25.29/ex25_29.sce create mode 100755 273/CH25/EX25.3/ex25_3.sce create mode 100755 273/CH25/EX25.30/ex25_30.sce create mode 100755 273/CH25/EX25.4/ex25_4.sce create mode 100755 273/CH25/EX25.5/ex25_5.sce create mode 100755 273/CH25/EX25.6/ex25_6.sce create mode 100755 273/CH25/EX25.7/ex25_7.sce create mode 100755 273/CH25/EX25.8/ex25_8.sce create mode 100755 273/CH25/EX25.9/ex25_9.sce (limited to '273/CH25') diff --git a/273/CH25/EX25.1/ex25_1.sce b/273/CH25/EX25.1/ex25_1.sce new file mode 100755 index 000000000..c306e35dd --- /dev/null +++ b/273/CH25/EX25.1/ex25_1.sce @@ -0,0 +1,14 @@ +clc;clear; +//Example 25.1 +//calculation of sum of two binary numbers + +//given values +X='0011';//first binary number +Y='0101';//second binary number + +//calculation +x=bin2dec(X);//decimal equivalent +y=bin2dec(Y);//decimal equivalent +z=x+y; +Z=dec2bin(z); +disp(Z,'Sum of the given binary numbers is ') diff --git a/273/CH25/EX25.10/ex25_10.sce b/273/CH25/EX25.10/ex25_10.sce new file mode 100755 index 000000000..ccea4348e --- /dev/null +++ b/273/CH25/EX25.10/ex25_10.sce @@ -0,0 +1,14 @@ +clc; +clear; +//example 25.10 +//binary division + +format('v',8);//changing the default precision to 8 +a=11001;//first number +b=100;//second number +A=bin21dec(a);//converting a in to decimal number +B=bin21dec(b);//converting b in to decimal number +S=A/B; //multiply the two decimal numbers +temp=dec21bin(S);//converting the decimal product back to binary + +disp(temp,'quotient is');//displaying the final output \ No newline at end of file diff --git a/273/CH25/EX25.11/ex25_11.sce b/273/CH25/EX25.11/ex25_11.sce new file mode 100755 index 000000000..71daf57ad --- /dev/null +++ b/273/CH25/EX25.11/ex25_11.sce @@ -0,0 +1,14 @@ +clc;clear; +//Example 25.11 +//calculation of sum of two octal numbers + +//given values +X='256';//divident +Y='437';//divisor + +//calculation +x=oct2dec(X);//decimal equivalent +y=oct2dec(Y);//decimal equivalent +z=x+y; +Z=dec2oct(z);//binary equivalent +disp(Z,'sum of the given octal numbers is') diff --git a/273/CH25/EX25.12/ex25_12.sce b/273/CH25/EX25.12/ex25_12.sce new file mode 100755 index 000000000..ef9fd09c8 --- /dev/null +++ b/273/CH25/EX25.12/ex25_12.sce @@ -0,0 +1,14 @@ +clc;clear; +//Example 25.12 +//calculation of product of two octal numbers + +//given values +X='15';//divident +Y='24';//divisor + +//calculation +x=oct2dec(X);//decimal equivalent +y=oct2dec(Y);//decimal equivalent +z=x*y; +Z=dec2oct(z);//binary equivalent +disp(Z,'product of the given octal numbers is') diff --git a/273/CH25/EX25.13/ex25_13.sce b/273/CH25/EX25.13/ex25_13.sce new file mode 100755 index 000000000..1152138b0 --- /dev/null +++ b/273/CH25/EX25.13/ex25_13.sce @@ -0,0 +1,28 @@ +clc;clear; +//Example 25.13 +//calculation of sum of hexadecimal numbers + +//given values +X1='C'; +X2='A'; +X3='E'; +Y1='3'; +Y2='2'; +Y3='D'; + +//calculation +x1=hex2dec(X1);//decimal equivalent +x2=hex2dec(X2);//decimal equivalent +x3=hex2dec(X3);//decimal equivalent +y1=hex2dec(Y1);//decimal equivalent +y2=hex2dec(Y2);//decimal equivalent +y3=hex2dec(Y3);//decimal equivalent +z1=x1+y1; +z2=x2+y2; +z3=x3+y3; +Z1=dec2hex(z1);//binary equivalent of sum +Z2=dec2hex(z2);//binary equivalent of sum +Z3=dec2hex(z3);//binary equivalent of sum +disp(Z1,'sum of the first set of hexadecimal numbers is'); +disp(Z2,'sum of the second set of hexadecimal numbers is'); +disp(Z3,'sum of the thirdm set of hexadecimal numbers is'); diff --git a/273/CH25/EX25.14/ex25_14.sce b/273/CH25/EX25.14/ex25_14.sce new file mode 100755 index 000000000..f4691d9b4 --- /dev/null +++ b/273/CH25/EX25.14/ex25_14.sce @@ -0,0 +1,10 @@ +clc;clear; +//Example 25.13 +//conversion of binary to decimal + +//given values +X=10.101;//binary number + +//calculation +Z=(1*2^1)+(0*2^0)+(1*2^-1)+(0*2^-2)+(1*2^-3); +disp(Z,'decimal equivalent of the given binary number is') diff --git a/273/CH25/EX25.15/ex25_15.sce b/273/CH25/EX25.15/ex25_15.sce new file mode 100755 index 000000000..2584cf8d5 --- /dev/null +++ b/273/CH25/EX25.15/ex25_15.sce @@ -0,0 +1,10 @@ +clc;clear; +//Example 25.15 +//conversion of decimal to binary + +//given values +X=43;//decimal number + +//calculation +Z=dec2bin(X); +disp(Z,'binary equivalent of the given decimal number is'); diff --git a/273/CH25/EX25.16/ex25_16.sce b/273/CH25/EX25.16/ex25_16.sce new file mode 100755 index 000000000..ed4512380 --- /dev/null +++ b/273/CH25/EX25.16/ex25_16.sce @@ -0,0 +1,43 @@ +clc;//clears the command window +clear;//clears all the variables +//example 25.16 +//decimal to binary conversion + +format('v',18);//changing the default prcision to 20 significant digits + +i=1;x=1;//flag bits + +dec=43.3125;//given decimal number which should be expressed in binary +temp2=floor(dec);//separating integer part from the given number +temp4=modulo(dec,1);//separating decimal part from the given number + +while(temp2>0)//storing each integer digit in vector for convenience + p(i)=(modulo(floor(temp2),2)) + temp2=floor(temp2/2); + i=i+1; +end + +temp2=0;//clearing temporary variable 'temp2' + +for j=1:length(p) +//multipliying bits of integer part with their position values and adding + temp2=temp2+(p(j)*10^(j-1)); +end + +while(temp4~=0) //storing each decimal digit in vector for convenience + temp4=temp4*2; + d(x)=floor(temp4); + x=x+1; + temp4=modulo(temp4,1); +end + +temp5=0;//clearing temporary variable 'temp5' + +for j=1:length(d) +//multipliying bits of decimal part with their position values and adding + temp5=temp5+(10^(-1*j)*d(j)) +end + +temp3=temp2+temp5; +//finally adding both the integer and decimal parts to get total output. +disp(temp3,'the equivalent binary number is'); \ No newline at end of file diff --git a/273/CH25/EX25.17/ex25_17.sce b/273/CH25/EX25.17/ex25_17.sce new file mode 100755 index 000000000..0d431a9d1 --- /dev/null +++ b/273/CH25/EX25.17/ex25_17.sce @@ -0,0 +1,39 @@ +clc;//clears the command window +clear;//clears all the variables +//example 25.17 +//decimal to octa conversion + +format('v',8);//making the default precision to 8 significant digits +i=1;w=1; +dec=375.23;//given decimal number which should be expressed in base 8 +temp=modulo(dec,1);//separating decimal part from the given number +temp2=floor(dec);//separating integer part from the given number + + +while(temp2>0)//storing each integer digit in vector for convenience + p(i)=(modulo(floor(temp2),8)) + temp2=floor(temp2/8); + i=i+1; +end + +temp2=0;//clearing temporary variable 'temp2' + +for j=1:length(p) +//multipliying bits of integer part with their position values and adding + temp2=temp2+(p(j)*10^(j-1)); +end + +while(temp~=0) //storing each decimal digit in vector for convenience + temp=temp*8; + q(w)=floor(temp); + w=w+1; + temp=modulo(temp,1); +end + +temp1=0; //flag bit +for k=1:length(q) +//multipliying bits of decimal part with their position values and adding + temp1=temp1+(10^(-1*k)*q(k)); +end +temp3=temp2+temp1; +disp(temp3,'octal number is'); \ No newline at end of file diff --git a/273/CH25/EX25.18/ex25_18.sce b/273/CH25/EX25.18/ex25_18.sce new file mode 100755 index 000000000..28b74e383 --- /dev/null +++ b/273/CH25/EX25.18/ex25_18.sce @@ -0,0 +1,11 @@ +clc;clear; +//Example 25.18 +//ocatl to binary conversion + +//given values +X='257';//octal number + +//calculation +x=oct2dec(X);//decimal equivalent +Z=dec2bin(x); +disp(Z,'binary number is ') diff --git a/273/CH25/EX25.19/ex2519.sce b/273/CH25/EX25.19/ex2519.sce new file mode 100755 index 000000000..2eab4a0f2 --- /dev/null +++ b/273/CH25/EX25.19/ex2519.sce @@ -0,0 +1,81 @@ +clc;//clears the command window +clear;//clears all the variables +//example 25.19 +//octal to binary conversion + +format('v',8);//setting the default precision to 8 + +i=1;w=1; + +bin=34.56; //Given octal number which we need to be convert into binary +temp1=floor(bin);//separating integer part from the given number +temp0=modulo(bin,1);//separating decimal part from the given number +temp2=temp0*10^2;//converting decimal value to interger for convenience +while(temp1>0) //storing each integer digit in vector for convenience + p(i)=modulo(temp1,10); + temp1=round(temp1/10); + i=i+1; +end + +while(temp2>0) //storing each decimal digit in vector for convenience + q(w)=modulo(temp2,10); + temp2=floor(temp2/10); + w=w+1; + +end +temp1=0; //clearing temporary variable 'temp1 + +for i=1:2 +//multipliying bits of decimal part with their position values and adding + temp1=temp1+(p(i)*8^(i-1)); +end + +temp2=0;//clearing temporary variable 'temp2' +for z=1:2 +//multipliying bits of decimal part with their position values and adding + temp2=temp2+(q(z)*8^(-1*(3-z))); + +end + +temp=temp1+temp2; +//adding both integer and decimal parts to get total deciaml value. +dec=temp; + +temp2=floor(dec); //separating integer part from the given number +temp3=modulo(dec,1);//separating decimal part from the given number +format('v',18);//setting the default precision to 8 + +i=1;x=1;//flag bits + +while(temp2>0)//storing each integer digit in vector for convenience + p(i)=(modulo(floor(temp2),2)) + temp2=floor(temp2/2); + i=i+1; +end + +temp2=0; //clears temporary variable 'temp2' + +for j=1:length(p) +//multipliying bits of integer part with their position values and adding + temp2=temp2+(p(j)*10^(j-1)); +end + +temp4=modulo(temp3,1); + +while(temp4~=0)//storing each decimal digit in vector for convenience + temp4=temp4*2; + d(x)=floor(temp4); + x=x+1; + temp4=modulo(temp4,1); +end + +temp5=0; //clears temporary variable 'temp2' + +for j=1:length(d) +//multipliying bits of decimal part with their position values and adding + temp5=temp5+(10^(-1*j)*d(j)) +end + +temp=temp2+temp5; +//finally adding both the integer and decimal parts to get total output. +disp(temp,'binary number is'); \ No newline at end of file diff --git a/273/CH25/EX25.2/ex25_2.sce b/273/CH25/EX25.2/ex25_2.sce new file mode 100755 index 000000000..e77f5a459 --- /dev/null +++ b/273/CH25/EX25.2/ex25_2.sce @@ -0,0 +1,13 @@ +clc; +clear; +//example 25.2 +//addition of binary numbers + +a=1010.00; //first number +b=0011.11; //second number +A=bin21dec(a); //converting a in to decimal number +B=bin21dec(b); //converting b in to decimal number +S=A+B; //adding the two decimal numbers +temp=dec21bin(S); //converting the decimal sum back to binary +format('v',10); //changing the default precision to 8 +disp(temp,'sum is'); //displaying the final output \ No newline at end of file diff --git a/273/CH25/EX25.20/ex2520.sce b/273/CH25/EX25.20/ex2520.sce new file mode 100755 index 000000000..4bbcf47fc --- /dev/null +++ b/273/CH25/EX25.20/ex2520.sce @@ -0,0 +1,75 @@ +clc;//clears the command window +clear;//clears all the variables +i=1;w=1; +bin=1011.01101;//Given binary number which we need to be convert into octal + +//conversion to decimal first +temp1=floor(bin);//separating integer part from the given number +temp2=modulo(bin,1);//separating decimal part from the given number +temp2=temp2*10^5;//converting decimal value to integer for convenience +while(temp1>0)//storing each integer digit in vector for convenience + p(i)=modulo(temp1,10); + temp1=floor(temp1/10); + i=i+1; +end +while(temp2>0)//storing each decimal digit in vector for convenience + q(w)=modulo(temp2,2); + temp2=(temp2/10); + temp2=floor(temp2); + w=w+1; +end +temp1=0;//flag bit +for i=1:length(p)//checking whether it is a binary number or not + if(p(i)>1) then + disp('not a binary number'); + abort; + end +end +for i=1:length(p) +//multipliying bits of integer part with their position values and adding + temp1=temp1+(p(i)*2^(i-1)); +end +temp2=0;//flag bit +for z=1:length(q) +//multipliying bits of decimal part with their position values and adding + temp2=temp2+(q(z)*2^(-1*(6-z))); +end +dec=temp1+temp2; +//finally adding both the integer and decimal parts to get decimal equivalent + +//conversion from decimal to octal + +format('v',8);//making the default precision to 8 significant digits +i=1;w=1; + +temp=modulo(dec,1);//separating decimal part from the given number +temp2=floor(dec);//separating integer part from the given number + + +while(temp2>0)//storing each integer digit in vector for convenience + r(i)=(modulo(floor(temp2),8)) + temp2=floor(temp2/8); + i=i+1; +end + +temp2=0;//clearing temporary variable 'temp2' + +for j=1:length(r) +//multipliying bits of integer part with their position values and adding + temp2=temp2+(r(j)*10^(j-1)); +end + +while(temp~=0) //storing each decimal digit in vector for convenience + temp=temp*8; + s(w)=floor(temp); + w=w+1; + temp=modulo(temp,1); +end + +temp1=0; //flag bit +for k=1:length(s) +//multipliying bits of decimal part with their position values and adding + temp1=temp1+(10^(-1*k)*s(k)); +end +temp3=temp2+temp1; +disp(temp3,'octal number is'); diff --git a/273/CH25/EX25.21/ex25_21.sce b/273/CH25/EX25.21/ex25_21.sce new file mode 100755 index 000000000..e5ca65811 --- /dev/null +++ b/273/CH25/EX25.21/ex25_21.sce @@ -0,0 +1,10 @@ +clc;clear; +//Example 25.21 +//hexadecimal to decimal conversion + +//given values +X='AC5';//hexadecimal number + +//calculation +x=hex2dec(X);//decimal equivalent +disp(x,'decimal number is ') diff --git a/273/CH25/EX25.22/ex2522.sce b/273/CH25/EX25.22/ex2522.sce new file mode 100755 index 000000000..24b2edfac --- /dev/null +++ b/273/CH25/EX25.22/ex2522.sce @@ -0,0 +1,29 @@ +clc;//clears the command window +clear;//clears all the variables +//example 25.22 +//decimal to hexadecimal conversion +format('v',4);//making the default precision to 8 significant digits +dec=379.54;//given decimal +w=1;i=1; + +temp1=floor(dec);//separating integer part from the given number +temp2=modulo(dec,1);//separating decimal part from the given number +x=dec2hex(temp1);//hexadecimal equivalent of integer part +s=0; + +while(temp2~=0) //storing each decimal digit in vector for convenience + temp2=temp2*16; + q(w)=floor(temp2); + s=s+1;//counter of a + a(w)=dec2hex(q(w)); + w=w+1; + temp2=modulo(temp2,1); +end +f=a(1); +for i=2:s + f=f+a(i); +end +b='.';//for concatenating to get the decimal part of hexadecimal +hex=x+b+f;//concatenating integer and decimal part +disp(hex,'hexadecimal equivalent is'); + diff --git a/273/CH25/EX25.23/ex25_23.sce b/273/CH25/EX25.23/ex25_23.sce new file mode 100755 index 000000000..af6d6a41c --- /dev/null +++ b/273/CH25/EX25.23/ex25_23.sce @@ -0,0 +1,11 @@ +clc;clear; +//Example 25.23 +//hexadecimal to binary conversion + +//given values +X='7AB';//hexadecimal number + +//calculation +x=hex2dec(X);//decimal equivalent +z=dec2bin(x); +disp(z,'binary number is '); diff --git a/273/CH25/EX25.24/ex25_24.sce b/273/CH25/EX25.24/ex25_24.sce new file mode 100755 index 000000000..060dff858 --- /dev/null +++ b/273/CH25/EX25.24/ex25_24.sce @@ -0,0 +1,11 @@ +clc;clear; +//Example 25.24 +//binary to hexadecimal conversion + +//given values +X='1011101';//binary number + +//calculation +x=bin2dec(X);//decimal equivalent +z=dec2hex(x); +disp(z,'hexadecimal number is '); diff --git a/273/CH25/EX25.25/ex25_25.sce b/273/CH25/EX25.25/ex25_25.sce new file mode 100755 index 000000000..e44212631 --- /dev/null +++ b/273/CH25/EX25.25/ex25_25.sce @@ -0,0 +1,97 @@ + +clc; +clear; +//Example 25.25 +//substraction by one's complement method +//aaa=input(" Enter the first no (in decimal) :"); +//bb=input(" Enter the number from which first no has to be substracted:"); +bb=14; +aaa=-7;// substraction is addition of negative number +if aaa<0 then + aa=-1*aaa; +else aa=aaa; +end +a=0; +b=0; +q=0; +for i=1:5 //converting from decimal to binary + x=modulo(aa,2); + a= a + (10^q)*x; + aa=aa/2; + aa=floor(aa); + q=q+1; +end +q=0; +for i=1:5 //converting from decimal to binary + y=modulo(bb,2); + b= b + (10^q)*y; + bb=bb/2; + bb=floor(bb); + q=q+1; +end +for i=1:5 + a1(i)=modulo(a,10); + a=a/10; + a=round(a); + +end +for i=1:5 + b1(i)=modulo(b,10); + b=b/10; + b=round(b); +end; +if aaa<0 then// making one's complement if number is less than zero + for i=1:5 + a1(i)=bitcmp(a1(i),1); + end + + car(1)=0; + +for i=1:5 + c1(i)=a1(i)+b1(i)+car(i); + if c1(i)== 2 then + car(i+1)= 1; + c1(i)=0; + elseif c1(i)==3 then + car(i+1)= 1; + c1(i)=1; + else + car(i+1)=0; + end; +end; +car2(1)=car(6); +re=0; +format('v',18); + for i=1:5 + re=re+(c1(i)*(10^(i-1))) //result of one's complement addition + end; + + + +for i=1:5 + s(i)=modulo(re,10); + re=re/10; + re=round(re); +end; + +for i=1:5 + re1(i)=s(i)+car2(i);//addition of carry after one's complement addition + if re1(i)== 2 then + car2(i+1)= 1; + re1(i)=0; + elseif re1(i)==3 then + car2(i+1)= 1; + re1(i)=1; + else + car2(i+1)=0; + end; +end; + + re2=0; +format('v',18); + for i=1:5 + re2=re2+(re1(i)*(10^(i-1))) + end; + + disp(re,'difference is') + \ No newline at end of file diff --git a/273/CH25/EX25.26/ex25_26sce.sce b/273/CH25/EX25.26/ex25_26sce.sce new file mode 100755 index 000000000..792f66adf --- /dev/null +++ b/273/CH25/EX25.26/ex25_26sce.sce @@ -0,0 +1,88 @@ + +clc; +clear; +//example 25.26 +//substraction by one's complement method +//a=input(" Enter the first no (binary) :"); +//b=input(" Enter the number from which first no has to be substracted:"); +a=10001; +b=10011; +q=0; + +for i=1:5 + a1(i)=modulo(a,10); + a=a/10; + a=round(a); + +end +for i=1:5 + b1(i)=modulo(b,10); + b=b/10; + b=round(b); +end; + for i=1:5//making one's complement of number to be substracted + a1(i)=bitcmp(a1(i),1); +end + +car(1)=0; + +for i=1:5 + c1(i)=a1(i)+b1(i)+car(i); + if c1(i)== 2 then + car(i+1)= 1; + c1(i)=0; + elseif c1(i)==3 then + car(i+1)= 1; + c1(i)=1; + else + car(i+1)=0; + end; +end; +car2(1)=car(6); +re=0; +format('v',18); +for i=1:5 + re=re+(c1(i)*(10^(i-1))) //result of one's complement addition +end; + + +for i=1:5 + s(i)=modulo(re,10); + re=re/10; + re=round(re); +end; +if car2(1)==1 then// checking carry + +for i=1:5 + re1(i)=s(i)+car2(i);//addition of carry after one's complement addition + if re1(i)== 2 then + car2(i+1)= 1; + re1(i)=0; + elseif re1(i)==3 then + car2(i+1)= 1; + re1(i)=1; + else + car2(i+1)=0; + end; +end; + + re2=0; +format('v',18); + for i=1:5 + re2=re2+(re1(i)*(10^(i-1))) + end; +disp(re2,'difference is') ; + +else + for i=1:5 + re1(i)=bitcmp(s(i),1); + end + re2=0; + for i=1:5 + re2=re2+(re1(i)*(10^(i-1))) + end; + re2=-1*re2; + disp(re2,'difference is') ; + end; + + \ No newline at end of file diff --git a/273/CH25/EX25.27/ex25_27sce.sce b/273/CH25/EX25.27/ex25_27sce.sce new file mode 100755 index 000000000..0ee5e2bdf --- /dev/null +++ b/273/CH25/EX25.27/ex25_27sce.sce @@ -0,0 +1,88 @@ + +clc; +clear; +//example 25.27 +//substraction by one's complement method +//a=input(" Enter the first no (binary) :"); +//b=input(" Enter the number from which first no has to be substracted:"); +a=10011; +b=10001; +q=0; + +for i=1:5 + a1(i)=modulo(a,10); + a=a/10; + a=round(a); +end +for i=1:5 + b1(i)=modulo(b,10); + b=b/10; + b=round(b); +end; +for i=1:5//making one's complement of number to be substracted + a1(i)=bitcmp(a1(i),1); +end + +car(1)=0; + +for i=1:5 + c1(i)=a1(i)+b1(i)+car(i); + if c1(i)== 2 then + car(i+1)= 1; + c1(i)=0; + elseif c1(i)==3 then + car(i+1)= 1; + c1(i)=1; + else + car(i+1)=0; + end; +end; +car2(1)=car(6); +re=0; +format('v',18); +for i=1:5 + re=re+(c1(i)*(10^(i-1))) //result of one's complement addition +end; + +for i=1:5 + s(i)=modulo(re,10); + re=re/10; + re=round(re); +end; +if car2(1)==1 then// checking carry + +for i=1:5 + re1(i)=s(i)+car2(i);//addition of carry after one's complement addition + if re1(i)== 2 then + car2(i+1)= 1; + re1(i)=0; + elseif re1(i)==3 then + car2(i+1)= 1; + re1(i)=1; + else + car2(i+1)=0; + end; +end; + + re2=0; +format('v',18); + for i=1:5 + re2=re2+(re1(i)*(10^(i-1))) + end; + re2= -1*re2; +disp(re2,'difference is') ; + +else + for i=1:5 + re1(i)=bitcmp(s(i),1); + end + re2=0; + for i=1:5 + re2=re2+(re1(i)*(10^(i-1))) + end; + re2=-1*re2; + disp(re2,'difference is') ; + +end; + + \ No newline at end of file diff --git a/273/CH25/EX25.28/ex25_28sce.sce b/273/CH25/EX25.28/ex25_28sce.sce new file mode 100755 index 000000000..21afe816f --- /dev/null +++ b/273/CH25/EX25.28/ex25_28sce.sce @@ -0,0 +1,35 @@ +clc; +clear; +//example25.28 +//finiding two's complement +//a=input(" Enter the number (binary) :"); +a=1010; +for i=1:4 + a1(i)=modulo(a,10); + a=a/10; + a=round(a); + +end +for i=1:4//making one's complement of number + a1(i)=bitcmp(a1(i),1); +end +for i=1:4 +car(1)=1; +re(i)=a1(i)+car(i);//addition of one to one's complement to contain two's complement + if re(i)== 2 then + car(i+1)= 1; + re(i)=0; + elseif re(i)==3 then + car(i+1)= 1; + re(i)=1; + else + car(i+1)=0; + end; +end; + + re2=0; +format('v',18); + for i=1:4 + re2=re2+(re(i)*(10^(i-1))) + end; +disp(re2,'two s complement is'); \ No newline at end of file diff --git a/273/CH25/EX25.29/ex25_29.sce b/273/CH25/EX25.29/ex25_29.sce new file mode 100755 index 000000000..db2827c54 --- /dev/null +++ b/273/CH25/EX25.29/ex25_29.sce @@ -0,0 +1,108 @@ + +clc; +clear; +//Example 25.29 +//addition of negative number by by two's complement method +//bb=input(" Enter the first no (in decimal) :"); +//aaa=input(" Enter the negative number that has to be added"); +bb=14; +aaa=-7; +if aaa<0 then + aa=-1*aaa; +else aa=aaa; +end +a=0; +b=0; +q=0; +for i=1:5 //converting from decimal to binary + x=modulo(aa,2); + a= a + (10^q)*x; + aa=aa/2; + aa=floor(aa); + q=q+1; +end +q=0; +for i=1:5 //converting from decimal to binary + y=modulo(bb,2); + b= b + (10^q)*y; + bb=bb/2; + bb=floor(bb); + q=q+1; +end +for i=1:5 + a1(i)=modulo(a,10); + a=a/10; + a=round(a); + +end +for i=1:5 + b1(i)=modulo(b,10); + b=b/10; + b=round(b); +end; +if aaa<0 then// making one's complement of the negative number + for i=1:5 + a1(i)=bitcmp(a1(i),1); + end + + car(1)=0; + +for i=1:5 + c1(i)=a1(i)+b1(i)+car(i); + if c1(i)== 2 then + car(i+1)= 1; + c1(i)=0; + elseif c1(i)==3 then + car(i+1)= 1; + c1(i)=1; + else + car(i+1)=0; + end; +end; +re=0; +format('v',18); + for i=1:5 + re=re+(c1(i)*(10^(i-1))) //result of one's complement addition + end; +for i=1:5 + s(i)=modulo(re,10); + re=re/10; + re=round(re); +end; +if car(6)==1 then// checking carry + car2(1)=1; + +for i=1:5 + re1(i)=s(i)+car2(i);//addition of carry after one's complement addition + if re1(i)== 2 then + car2(i+1)= 1; + re1(i)=0; + elseif re1(i)==3 then + car2(i+1)= 1; + re1(i)=1; + else + car2(i+1)=0; + end; +end; + + re2=0; +format('v',18); + for i=1:5 + re2=re2+(re1(i)*(10^(i-1))) + end; + + disp(re2,'difference is') ; + +else + for i=1:5 + re1(i)=bitcmp(s(i),1); + end + re2=0; + for i=1:5 + re2=re2+(re1(i)*(10^(i-1))) + end; + re2=-1*re2; + disp(re2,'difference is') ; + end; + + \ No newline at end of file diff --git a/273/CH25/EX25.3/ex25_3.sce b/273/CH25/EX25.3/ex25_3.sce new file mode 100755 index 000000000..44728798c --- /dev/null +++ b/273/CH25/EX25.3/ex25_3.sce @@ -0,0 +1,13 @@ +clc; +clear; +//example 25.3 +//addition of two binary numbers + +a=1011.01; //first number +b=1101.11; //second number +A=bin21dec(a); //converting a in to decimal number +B=bin21dec(b); //converting b in to decimal number +S=A+B; //adding the two decimal numbers +temp=dec21bin(S); //converting the decimal sum back to binary +format('v',10); //changing the default precision to 8 +disp(temp,'sum is'); //displaying the final output \ No newline at end of file diff --git a/273/CH25/EX25.30/ex25_30.sce b/273/CH25/EX25.30/ex25_30.sce new file mode 100755 index 000000000..6ea5d011c --- /dev/null +++ b/273/CH25/EX25.30/ex25_30.sce @@ -0,0 +1,88 @@ + +clc; +clear; +//example 25.27 +//substarction by one's complement method +//a=input(" Enter the first no (binary) :"); +//b=input(" Enter the number from which first no has to be substracted:"); +a=10011; +b=10001; +q=0; + +for i=1:5 + a1(i)=modulo(a,10); + a=a/10; + a=round(a); +end +for i=1:5 + b1(i)=modulo(b,10); + b=b/10; + b=round(b); +end; +for i=1:5//making one's complement of number to be substracted + a1(i)=bitcmp(a1(i),1); +end + +car(1)=0; + +for i=1:5 + c1(i)=a1(i)+b1(i)+car(i); + if c1(i)== 2 then + car(i+1)= 1; + c1(i)=0; + elseif c1(i)==3 then + car(i+1)= 1; + c1(i)=1; + else + car(i+1)=0; + end; +end; + +re=0; +format('v',18); +for i=1:5 + re=re+(c1(i)*(10^(i-1))) //result of one's complement addition +end; + +for i=1:5 + s(i)=modulo(re,10); + re=re/10; + re=round(re); +end; +if car(6)==1 then// checking carry + +for i=1:5 + re1(i)=s(i)+car2(i);//addition of carry after one's complement addition + if re1(i)== 2 then + car2(i+1)= 1; + re1(i)=0; + elseif re1(i)==3 then + car2(i+1)= 1; + re1(i)=1; + else + car2(i+1)=0; + end; +end; + + re2=0; +format('v',18); + for i=1:5 + re2=re2+(re1(i)*(10^(i-1))) + end; + re2= -1*re2; +disp(re2,'difference is') ; + +else + for i=1:5 + re1(i)=bitcmp(s(i),1); + end + re2=0; + for i=1:5 + re2=re2+(re1(i)*(10^(i-1))) + end; + re2=-1*re2; + disp(re2,'difference is') ; + +end; + + \ No newline at end of file diff --git a/273/CH25/EX25.4/ex25_4.sce b/273/CH25/EX25.4/ex25_4.sce new file mode 100755 index 000000000..d7926693d --- /dev/null +++ b/273/CH25/EX25.4/ex25_4.sce @@ -0,0 +1,14 @@ +clc;clear; +//Example 25.4 +//calculation of difference of two binary numbers + +//given values +X='1011';//first binary number +Y='0101';//second binary number + +//calculation +x=bin2dec(X);//decimal equivalent +y=bin2dec(Y);//decimal equivalent +z=x-y; +Z=dec2bin(z); +disp(Z,'difference of the given binary numbers '); \ No newline at end of file diff --git a/273/CH25/EX25.5/ex25_5.sce b/273/CH25/EX25.5/ex25_5.sce new file mode 100755 index 000000000..0c10b86c1 --- /dev/null +++ b/273/CH25/EX25.5/ex25_5.sce @@ -0,0 +1,14 @@ +clc;clear; +//Example 25.5 +//calculation of difference of two binary numbers + +//given values +X='1000';//first binary number +Y='0011';//second binary number + +//calculation +x=bin2dec(X);//decimal equivalent +y=bin2dec(Y);//decimal equivalent +z=x-y; +Z=dec2bin(z); +disp(Z,'difference of the given binary numbers ') diff --git a/273/CH25/EX25.6/ex25_6.sce b/273/CH25/EX25.6/ex25_6.sce new file mode 100755 index 000000000..af36c993c --- /dev/null +++ b/273/CH25/EX25.6/ex25_6.sce @@ -0,0 +1,14 @@ +clc; +clear; +//example 25.6 +//binary substraction + +format('v',8);//changing the default precision to 8 +a=1001.01;//first number +b=0011.10;//second number +A=bin21dec(a);//converting a in to decimal number +B=bin21dec(b);//converting b in to decimal number +S=A-B; //multiply the two decimal numbers +temp=dec21bin(S);//converting the decimal product back to binary + +disp(temp,'difference is');//displaying the final output \ No newline at end of file diff --git a/273/CH25/EX25.7/ex25_7.sce b/273/CH25/EX25.7/ex25_7.sce new file mode 100755 index 000000000..72e35ec9c --- /dev/null +++ b/273/CH25/EX25.7/ex25_7.sce @@ -0,0 +1,14 @@ +clc;clear; +//Example 25.7 +//calculation of product of two binary numbers + +//given values +X='10101';//first binary number with last two digits in fractional part +Y='101';//second binary number with last two digits in fractional part + +//calculation +x=bin2dec(X);//decimal equivalent +y=bin2dec(Y);//decimal equivalent +z=x*y; +Z=dec2bin(z); +disp(Z,'product of the given binary numbers is ') diff --git a/273/CH25/EX25.8/ex25_8.sce b/273/CH25/EX25.8/ex25_8.sce new file mode 100755 index 000000000..381ed11a3 --- /dev/null +++ b/273/CH25/EX25.8/ex25_8.sce @@ -0,0 +1,14 @@ +clc; +clear; +//example 25.8 +//binary multiplication + +format('v',8);//changing the default precision to 8 +a=10101.01;//first number +b=110.10;//second number +A=bin21dec(a);//converting a in to decimal number +B=bin21dec(b);//converting b in to decimal number +S=A*B; //multiply the two decimal numbers +temp=dec21bin(S);//converting the decimal product back to binary + +disp(temp,'product is');//displaying the final output \ No newline at end of file diff --git a/273/CH25/EX25.9/ex25_9.sce b/273/CH25/EX25.9/ex25_9.sce new file mode 100755 index 000000000..b369967b1 --- /dev/null +++ b/273/CH25/EX25.9/ex25_9.sce @@ -0,0 +1,14 @@ +clc;clear; +//Example 25.9 +//calculation of quotient of two binary numbers + +//given values +X='1101001';//divident +Y='101';//divisor + +//calculation +x=bin2dec(X);//decimal equivalent +y=bin2dec(Y);//decimal equivalent +z=x/y; +Z=dec2bin(z); +disp(Z,'quotient of the given binary numbers with last two digits in fractional part is ') -- cgit