Extract each digit of a binary \ decimal number

873 Views Asked by At

How can one extract the digits of a binary \ decimal number. For example i have 100110111 to need to extract them only using +,-,*,/ and MOD. I can only use this LOOP Language. Most of the algorithms use floor function with decimal numbers, but i have no clou how to implement floor with this.

http://www.eugenkiss.com/projects/lgw/#exercises

1

There are 1 best solutions below

0
On BEST ANSWER

Although cumbersome, the following procedure can be employed to find out each digit. Maybe bounds on the while loops need to be adjusted $\pm1$.

$num = 100110111$

$count = 0$

$div = 10$

while $div\geq 10 \left\{\right.$

$\quad count = count +1$

$\quad div = num/10^{count}\left.\right\}$

initialize $digits$ array

$i = 0$

while $count\geq 0 \left\{\right.$

$\quad$ while $ num\geq 0 \left\{\right.$

$\quad \quad num = num - 10^{count +1}$

$\quad \quad dig[i] = dig[i]+1 \left.\right\}$

$\quad num = num + 10^{count +1}$

$\quad i = i +1$

$\quad count = count-1 \left.\right\}$