summaryrefslogtreecommitdiff
path: root/3836/CH9/EX9.10/Ex9_10.sce
diff options
context:
space:
mode:
Diffstat (limited to '3836/CH9/EX9.10/Ex9_10.sce')
-rw-r--r--3836/CH9/EX9.10/Ex9_10.sce38
1 files changed, 38 insertions, 0 deletions
diff --git a/3836/CH9/EX9.10/Ex9_10.sce b/3836/CH9/EX9.10/Ex9_10.sce
new file mode 100644
index 000000000..8a613eb8b
--- /dev/null
+++ b/3836/CH9/EX9.10/Ex9_10.sce
@@ -0,0 +1,38 @@
+clear
+//Initializaton
+
+no=34.6875 //decimal number
+n_int = int(no) // Extract the integral part
+n_frac = no-n_int // Extract the fractional part
+
+//Calculation
+
+bini = 0
+i = 1
+ni = n_int
+while (ni > 0)
+ rem = ni-int(ni/2)*2
+ ni = int(ni/2)
+ bini = bini + rem*i
+ i = i * 10
+end
+
+// Function to convert binary fraction to decimal fraction
+binf = 0
+i = 0.1,
+
+nf = n_frac
+
+while (nf > 0)
+ nf = nf*2
+ rem = int(nf)
+ nf = nf-rem
+ binf = binf + rem*i
+ i = i/10
+end
+
+
+
+//Result
+printf("\n Decimal equivalent of 34.6875 = %.4f",(bini+binf))
+