Message Boards Message Boards

0
|
5331 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

How to convert base 2 number to list of digits?

Posted 10 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.

Gary

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

yields

{{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
Posted 10 years ago

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

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

Group Abstract Group Abstract