How to convert the decimal number "18.25" to binary? I've been confused by the decimal points .25.
-
1This question appears to be blatantly off-topic as it has nothing to do with programming. You may be able to get help on [math.SE] instead. – Unihedron Aug 10 '14 at 04:27
2 Answers
Just like you divide this 18 by 2 repeatedly to form a decimal representation for it, you need to do the reverse to convert the decimal part of the number to binary. You need to multiply that decimal portion of the number by 2 repeatedly until it gives a standalone digit. The result(product) of the first multiplication will be the input to the second multiplication and this continues until we reach a stagnant steady integer value.
So, in your case, the 18.25's decimal part is 0.25.
Let's begin by multiplying it with 2.
0.25*2=0.5 // 0
0.5*2=1.0 // 1
Hunt finishes as we end up with the product coming as a standalone integer.
Also, the decimal to binary conversion of 18 is (10010)base 2
. This you can easily calculate as you know it,mentioned in the question.
Hence, the decimal representation for 18.25 will be (10010.01)base 2
---see,serially 01 in the order unlike the numbers where we traverse from bottom to top!
I hope it is clear.

- 18,735
- 7
- 49
- 73
with recursiveCTE(num) as (
select &EnterNum num from dual
union all
select trunc(num/2) from recursiveCTE
where trunc(num/2)> 0
),
ref as (SELECT num, mod(num, 2) bin_remainder from recursiveCTE)
select reverse(to_char(replace(wm_concat(bin_remainder), ','))) binary_num from ref;

- 3,868
- 8
- 27
- 32