Message Boards Message Boards

2 Replies
0 Total Likes
View groups...
Share this post:

How to convert base 2 number to list of digits?

Posted 9 years ago

This is a simple problem, but I've spent way too long trying to solve it.

I want to start with an irrational number, convert it to base 2, and then get a list of the individual digits in the number. Attached below is a screenshot with an example. The problem occurs because BaseForm output is not just the binary string, but also includes the subscript 2 at the end. But when this is used in RealDigits to get the list of digits, it objects. The last line in the screenshot gives the output I want, but I had to cut-and-paste the base 2 number (minus the subscript) to get it to work.

Any ideas? Thanks. Very much appreciated.


POSTED BY: Gary Lewis
2 Replies
Posted 9 years ago

My brain seizure is gone; what a relief. Thanks John!

POSTED BY: Gary Lewis
RealDigits[N[Sqrt[2] - 1, 6], 2]


{{1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1}, -1}
POSTED BY: John Doty
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract