2
$\begingroup$

I have number $-1e35$, and I'm supposed to convert it to binary. The answer is : $-1.10101001010110100101101...\text{e}–117.$

I can't figure out how to get this! and how we can calculate numbers partially as you see here. Originally it is a programming practice, but what I care about is the mathematical part.

I tried to solve it like this: $\log 10^{35}=\log 2^x.$ The result is: $116.666$.

My question is not exactly how to convert. I know how to convert smaller numbers, but I am confused with scientific notation, and how to represent part of the number.

$\endgroup$
1
  • $\begingroup$ Why is the binary exponent negative? $\endgroup$ Commented Feb 3, 2016 at 18:36

1 Answer 1

2
$\begingroup$

When you represent a number in decimal scientific notation, the base of the exponent is $10$, so $1E35=1\cdot 10^{35}$. In binary, the base is $2$, so you are trying to solve $1\cdot 10^{35}=m2^e$ where $1 \lt m \lt 10_2$ is the mantissa and $e$ is an integer exponent. To find $e$ we can take logs: $$1 \cdot 10^{35} = m2^e\\ 35 \log_2(10)=e+ \log_2 (m)\\e=\lfloor35 \log_2(10)\rfloor=116_{10}$$ Now to get the mantissa you can just subtract off powers of $2$ $$10^{35}-2^{116}=16923250263442757943512058732478464\\ \lfloor \log_2(16923250263442757943512058732478464)\rfloor=113$$ so we start with $1.001_2$ because the exponent dropped by $3$ $$16923250263442757943512058732478464-2^{113}=6538656546373102686451066074038272\\ \lfloor \log_2(6538656546373102686451066074038272)\rfloor=112$$ so our mantissa becomes $1.0011_2$ and so on until you get tired, your word fills up, or you get to the end. The final answer is $$1.001101000010011000010111001011000111010011011000001000101011100001111000111111101_2E116$$

$\endgroup$
11
  • $\begingroup$ i am trying to repair the math part of my brain , I've been away for a long time , in the sentence : so we start with 1.001(2) , 2 is the base ?? $\endgroup$
    – shayan
    Commented Feb 3, 2016 at 19:12
  • $\begingroup$ and another question , why you have rounded it to 116? $\endgroup$
    – shayan
    Commented Feb 3, 2016 at 19:36
  • 1
    $\begingroup$ Yes, binary means base 2. I took the floor to get $116$. We have $2^{116} \lt 10^{35} \lt 2^{117}$ and want $1 \lt m \lt 2$. $\endgroup$ Commented Feb 3, 2016 at 20:12
  • $\begingroup$ @RossMillikan I obtain $e = 35 \log_2 10 - \log_2 m$, then it is not clear why $e=\lfloor35 \log_2(10)\rfloor=116_{10}$, please, can you explain better? Thanks! $\endgroup$
    – JB-Franco
    Commented May 25, 2020 at 17:06
  • 1
    $\begingroup$ @JB-Franco: Take the base $10$ log of the first centered equation, which gives $35=e\log_{10}2+\log_{10}m$ Now use $\log_{10}2=\frac 1{\log_210}$ to move that term over and take the floor to get rid of $\log_{10}m$, which is between $0$ and $1$ $\endgroup$ Commented May 25, 2020 at 17:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .