I am trying to convert a number to binary without using BaseForm. Can anyone please tell me why this code isn’t working?
binarize =
a = Input["Enter No."];
convert = {}
While[a > 0, AppendTo[convert, Mod[a, 2]]],
a = Floor[Divide[a, 2]]
If[a == 0, True],
Break[]
Print[Reverse[convert]]
mthiel
(Marco Thiel)
2
Hi,
I think that this might work:
a = Input["Enter No."];
convert = {}
While[a > 0, AppendTo[convert, Mod[a, 2]];
a = Floor[Divide[a, 2]];]
Print[Reverse[convert]]
But why don’t you just use something like:
BaseForm[100, 2]
Cheers,
Marco
Thanks for the reply! It works! I am trying to convert the numbers without using built-in Wolfram Functions.
Hi Aryan,
What is the definition of “without using built-in Wolfram Functions”? What about this
Table[BitGet[a, i], {i, 1, BitLength[a]}]
or this
IntegerDigits[a, 2]