Is there a function that takes in a binary number and yields the corresponding decimal number, or vice versa?

129 Views Asked by At

For example,

f(10111010) = 186

f(101110101101001) = 23913

Correspondingly, is there an inverse function to this?

2

There are 2 best solutions below

0
On

There is a standard algorithm to convert between the representations of a number in different bases.

1
On

The function exists, because you just defined it. I believe what you meant to ask is, "does a simple formula exist for this function?" I don't think that there is a formula much simpler than performing the algorithm to do the conversion. I expect it would be a mess of fractions and floor functions and modulo reductions.