English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I know that 1024 is at the 10th position in a binary number : 2^10 = 1024. However, if I take the problem on the other side, at which position is 1024. How I can know that?

2007-05-06 04:43:26 · 2 answers · asked by margagn 1 in Science & Mathematics Mathematics

2 answers

If you are asking, "What is the highest bit set to 1 in a binary number given a number in base 10?", then you can do it this way:

‪‪‪‪‪‪‪‫‪‪b = ceil(log_2(n))

ceil() is the ceiling function: http://en.wikipedia.org/wiki/Ceiling_function
log_2() is logarithm base 2: http://en.wikipedia.org/wiki/Logarithm

In your example,

b = ceil(log_2(1024)) = ceil(log_10(1024)/log_10(2)) = 10

2007-05-06 07:26:55 · answer #1 · answered by _tessar_ 3 · 0 0

If the given number is is b you must solve
2^x=b so
x= ln(b)/ln(2)

2007-05-06 16:15:51 · answer #2 · answered by santmann2002 7 · 0 0

fedest.com, questions and answers