summaryrefslogtreecommitdiff
path: root/45/CH5/EX5.2/example_5_2.sce
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /45/CH5/EX5.2/example_5_2.sce
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 '45/CH5/EX5.2/example_5_2.sce')
-rwxr-xr-x45/CH5/EX5.2/example_5_2.sce40
1 files changed, 40 insertions, 0 deletions
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