summaryrefslogtreecommitdiff
path: root/45/CH5
diff options
context:
space:
mode:
Diffstat (limited to '45/CH5')
-rwxr-xr-x45/CH5/EX5.1/example_5_1.sce40
-rwxr-xr-x45/CH5/EX5.10/example_5_10.sce22
-rwxr-xr-x45/CH5/EX5.11/example_5_11.sce22
-rwxr-xr-x45/CH5/EX5.2/example_5_2.sce40
-rwxr-xr-x45/CH5/EX5.3/example_5_3.sce7
-rwxr-xr-x45/CH5/EX5.4/example_5_4.sce33
-rwxr-xr-x45/CH5/EX5.5/example_5_5.sce7
-rwxr-xr-x45/CH5/EX5.6/example_5_6.sce34
-rwxr-xr-x45/CH5/EX5.7/example_5_7.sce21
-rwxr-xr-x45/CH5/EX5.8/example_5_8.sce8
-rwxr-xr-x45/CH5/EX5.9/example_5_9.sce21
11 files changed, 255 insertions, 0 deletions
diff --git a/45/CH5/EX5.1/example_5_1.sce b/45/CH5/EX5.1/example_5_1.sce
new file mode 100755
index 000000000..47b0cc281
--- /dev/null
+++ b/45/CH5/EX5.1/example_5_1.sce
@@ -0,0 +1,40 @@
+//Example 5.1
+clc //clears the command window
+clear //clears all the variables
+p=1; //initialising variables
+q=1;
+z=0;
+b=0;
+w=0;
+f=0;
+format('v',18); //increasing the precision to 18 .
+//bin= input ("Enter the binary no to be converted to its decimal equivalent : ") // accepting the binary input from user
+bin=110.001;
+d= modulo(bin,1); //separating the decimal part and the integer part
+d=d*10^10;
+a=floor(bin); //removing the decimal part
+while(a>0) //Loop to take the binary bits of integer in to a matrix
+ r=modulo(a,10);
+ b(1,q)=r;
+ a=a/10;
+ a=floor(a);
+ q=q+1;
+end
+for m=1:q-1 //multipliying the bits of integer with their position values and adding
+ c=m-1;
+ f = f + b(1,m)*(2^c);
+end
+while(d>0) //Loop to take the binary bits of decimal in to a matrix
+ e=modulo(d,2)
+ w(1,p)=e
+ d=d/10;
+ d=floor(d)
+ p=p+1;
+ end
+for n=1:p-1 //multipliying the bits of decimal with their position values and adding
+ z=z+w(1,n)*(0.5)^(11-n);
+end
+z=z*10000; //rounding of to 4 decimal values
+z=round(z);
+z=z/10000;
+printf("The Decimal equivalent of the Binary number given is = %f",f+z); //Displaying the final result \ No newline at end of file
diff --git a/45/CH5/EX5.10/example_5_10.sce b/45/CH5/EX5.10/example_5_10.sce
new file mode 100755
index 000000000..7ce381e52
--- /dev/null
+++ b/45/CH5/EX5.10/example_5_10.sce
@@ -0,0 +1,22 @@
+//Example 5.10
+clc //clears the command window
+clear //clears the variables
+q=0;
+b=0;
+//a=input("enter the decimal no:")
+a=56000; // giving the value specified in the problem
+temp=a;
+format('v',18) //increasing the precision to 18
+a=floor(a);
+h=dec2hex(a);
+while(a>0) // converting to binary
+ x=modulo(a,2);
+ b= b + (10^q)*x;
+ a=a/2;
+ a=floor(a);
+ q=q+1;
+end
+printf("Given decimal number is : %d\n",temp)
+printf("The hexadecimal equivalent is = %s\n",h)
+ //displaying the results
+printf("The binary equivalent is = %f\n",b);
diff --git a/45/CH5/EX5.11/example_5_11.sce b/45/CH5/EX5.11/example_5_11.sce
new file mode 100755
index 000000000..80d8d5bfa
--- /dev/null
+++ b/45/CH5/EX5.11/example_5_11.sce
@@ -0,0 +1,22 @@
+//chapter 5
+//Example 5.11
+//Q.convert decimal numbers to its hexadecimal and binary equivalent ?
+//solution :
+clc //clears the command window
+clear //clears the variables
+q=0;
+b=0;
+a=input("Enter the decimal no:") //Enter the decimal nuber
+format('v',18) //increasing the precision to 18
+a=floor(a);
+h=dec2hex(a);
+while(a>0) // converting to binary
+ x=modulo(a,2);
+ b= b + (10^q)*x;
+ a=a/2;
+ a=floor(a);
+ q=q+1;
+end
+printf("The hexadecimal equivalent is = %s\n",h)
+ //displaying the results
+printf("The binary equivalent is = %f",b)
diff --git a/45/CH5/EX5.2/example_5_2.sce b/45/CH5/EX5.2/example_5_2.sce
new file mode 100755
index 000000000..659aaa8ce
--- /dev/null
+++ b/45/CH5/EX5.2/example_5_2.sce
@@ -0,0 +1,40 @@
+//Example 5.2
+clc //clears the command window
+clear //clears all the variables
+p=1; //initialising variables
+q=1;
+z=0;
+b=0;
+w=0;
+f=0;
+format('v',18); //increasing the precision to 18 .
+//bin= input ("Enter the binary no to be converted to its decimal equivalent : ") // accepting the binary input from user
+bin=1011.11;
+d= modulo(bin,1); //separating the decimal part and the integer part
+d=d*10^10;
+a=floor(bin); //removing the decimal part
+while(a>0) //Loop to take the binary bits of integer in to a matrix
+ r=modulo(a,10);
+ b(1,q)=r;
+ a=a/10;
+ a=floor(a);
+ q=q+1;
+end
+for m=1:q-1 //multipliying the bits of integer with their position values and adding
+ c=m-1;
+ f = f + b(1,m)*(2^c);
+end
+while(d>0) //Loop to take the binary bits of decimal in to a matrix
+ e=modulo(d,2)
+ w(1,p)=e
+ d=d/10;
+ d=floor(d)
+ p=p+1;
+ end
+for n=1:p-1 //multipliying the bits of decimal with their position values and adding
+ z=z+w(1,n)*(0.5)^(11-n);
+end
+z=z*10000; //rounding of to 4 decimal values
+z=round(z);
+z=z/10000;
+printf("The Decimal equivalent of the Binary number given is = %f",f+z); //Displaying the final result \ No newline at end of file
diff --git a/45/CH5/EX5.3/example_5_3.sce b/45/CH5/EX5.3/example_5_3.sce
new file mode 100755
index 000000000..a0418d98a
--- /dev/null
+++ b/45/CH5/EX5.3/example_5_3.sce
@@ -0,0 +1,7 @@
+//Example 5.3
+clc //clears the command window .
+clear //clears all the variables .
+format('v',18); //increasing the precision to 18 .
+n=2; /// given 2 mb
+dec = n * 2^20 ;
+printf("The decimal equivalent of 2Mb is = %f ",dec); //displaying the value.
diff --git a/45/CH5/EX5.4/example_5_4.sce b/45/CH5/EX5.4/example_5_4.sce
new file mode 100755
index 000000000..afe9156f1
--- /dev/null
+++ b/45/CH5/EX5.4/example_5_4.sce
@@ -0,0 +1,33 @@
+//Example 5.3
+clc //clears the command window
+clear //clears all the variables
+q=0;
+b=0;
+s=0;
+format('v',18); //increasing the precision to 18 .
+//a=input("Enter the decimal no to be converted to its binary equivalent : "); // accepting the decimal input from user
+a=23.6;
+d=modulo(a,1); //separating the decimal part and the integer part
+a=floor(a); //removing the decimal part
+
+while(a>0) //taking integer part in to a matrix and convert to equivalent binary
+ x=modulo(a,2);
+ b= b + (10^q)*x;
+ a=a/2;
+ a=floor(a);
+ q=q+1;
+end
+
+
+
+for i=1:10 // For values after decimal point converting to binary
+ d=d*2;
+ q=floor(d);
+ s=s+q/(10^i);
+ if d>=1 then
+ d=d-1;
+ end
+ end
+ k=b+s;
+printf("The binary equivalent of the given decimal number is = %f",k); // displaying the final result.
+ \ No newline at end of file
diff --git a/45/CH5/EX5.5/example_5_5.sce b/45/CH5/EX5.5/example_5_5.sce
new file mode 100755
index 000000000..450d8cd41
--- /dev/null
+++ b/45/CH5/EX5.5/example_5_5.sce
@@ -0,0 +1,7 @@
+//Example 5.5
+clc //clears the command window
+clear //clears all the variables
+format('v',18) //increasing the precision
+n=32; // given 32 1's
+dec=2^n - 1 ;
+printf("The decimal equivalent of 32 bit number with all 1s is = %f ",dec); // displaying the result
diff --git a/45/CH5/EX5.6/example_5_6.sce b/45/CH5/EX5.6/example_5_6.sce
new file mode 100755
index 000000000..ad9dd2880
--- /dev/null
+++ b/45/CH5/EX5.6/example_5_6.sce
@@ -0,0 +1,34 @@
+//Example 5.6
+clc //clears the command window
+clear //clears all the variables
+q=0;
+b=0;
+s=0;
+format('v',18); //increasing the precision to 18 .
+//a=input("Enter the decimal no to be converted to its binary equivalent : "); // accepting the decimal input from user
+a=363; //taking the value given in problem
+d=modulo(a,1); //separating the decimal part and the integer part
+a=floor(a); //removing the decimal part
+
+while(a>0) //taking integer part in to a matrix and convert to equivalent binary
+ x=modulo(a,2);
+ b= b + (10^q)*x;
+ a=a/2;
+ a=floor(a);
+ q=q+1;
+end
+
+
+
+for i=1:10 // For values after decimal point converting to binary
+ d=d*2;
+ q=floor(d);
+ s=s+q/(10^i);
+ if d>=1 then
+ d=d-1;
+ end
+ end
+ k=b+s;
+ disp("The give decimal number is 363")
+printf(" The binary equivalent of the given decimal number is = %f",k); // displaying the final result.
+ \ No newline at end of file
diff --git a/45/CH5/EX5.7/example_5_7.sce b/45/CH5/EX5.7/example_5_7.sce
new file mode 100755
index 000000000..3726a3193
--- /dev/null
+++ b/45/CH5/EX5.7/example_5_7.sce
@@ -0,0 +1,21 @@
+//Example 5.7
+clc //clears the command window
+clear //clears all the variables
+q=1;
+b=0;
+f=0;
+bin=input("Enter the 8-bit binary address :"); // Taking the input binary bits from the user
+a=floor(bin)
+while(a>0) //Loop to take the binary bits in to a matrix(array)
+ r=modulo(a,10);
+ b(1,q)=r;
+ a=a/10;
+ a=floor(a);
+ q=q+1;
+end
+for m=1:q-1 // converrting to decimal
+ c=m-1;
+ f = f + b(1,m)*(2^c);
+end
+c=dec2hex(f);
+printf("The hexadecimal equivalent of the given binary number is : %s",c); //displaying the value \ No newline at end of file
diff --git a/45/CH5/EX5.8/example_5_8.sce b/45/CH5/EX5.8/example_5_8.sce
new file mode 100755
index 000000000..79996b5aa
--- /dev/null
+++ b/45/CH5/EX5.8/example_5_8.sce
@@ -0,0 +1,8 @@
+//Example 5.8
+clc //clear the command window
+clear //clear the variables
+a=input("Enter the hexadecimal number to be converted into decimal(enter in a single quotation) : ") // taking the input from user
+d=hex2dec(a);
+printf("The decimal equivalent is : %d",d); //displaying the output
+
+
diff --git a/45/CH5/EX5.9/example_5_9.sce b/45/CH5/EX5.9/example_5_9.sce
new file mode 100755
index 000000000..406b61f7d
--- /dev/null
+++ b/45/CH5/EX5.9/example_5_9.sce
@@ -0,0 +1,21 @@
+//Example 5.9
+clc //clears the command window
+clear //clears the variables
+q=0;
+b=0;
+//a=input("enter the decimal no:")
+a=65535; // giving the value specified in the problem
+temp =a;
+format('v',18) //increasing the precision to 18
+a=floor(a);
+h=dec2hex(a);
+while(a>0) // converting to binary
+ x=modulo(a,2);
+ b= b + (10^q)*x;
+ a=a/2;
+ a=floor(a);
+ q=q+1;
+end
+printf("Given decimal number is : %d\n",temp)
+printf('The hexadecimal equivalent is = %s\n',h); //displaying the results
+printf('The binary equivalent is = %f',b ); \ No newline at end of file