Currently trying to write code that converts decimal floats to binary base form (I know BaseForm exists).
Currently I'm working with an example that takes 3.3 and converts it:
binary={}
x = Floor[3.3*2^8];
For[i = 0, i <= 9, i++,
remainder = Mod[x, 2];
x = Floor[x/2];
AppendTo[binary, remainder];
];
Print[FromDigits[Reverse[binary]]]
Which gives:
1101001100
Obviously the answer should have a . between 11 and 01001100, but I'm not quite sure how to implement this. Does anyone have any ideas (so it would work with all examples, not just 3.3).
Thanks!
RealDigits[3.3, 2]
and you can control the number of digits you want with the 3rd argument? $\endgroup$BaseForm[3.3, 2]
? $\endgroup$