Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.3K Views
|
3 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Convert a Number to Binary

Posted 6 years ago

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]]
POSTED BY: Aryan Deshpande
3 Replies
Posted 6 years ago
POSTED BY: Rohit Namjoshi

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

POSTED BY: Marco Thiel
POSTED BY: Aryan Deshpande
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard