8
$\begingroup$

How do I best represent the number $\pi$ in binary?

I have been thinking about it for sometime and, if it was me, I would use four bits for each digit, because four bits are sufficient to represent 10-based digits. Something like:

0011 , 0001 0100 0001 ... 

I wouldn't know, also, how to represent the decimal point here.

I hope my question is clear enough.

Update

I will put this into context. I didn't want to, because I thought you would find it stupid.

I want to make a full back tattoo, representing pi in binary so, what I am looking for is a way that will be more or less simple to scale, as I will want thousands of digits, and I want it to be precise.

  • 5
    Pray tell me, how do you represent 8 and 9 with 3 bits? I would just write $\pi$ in base 2: $\pi=11.0010\ldots=2+1+2^{-3}+\cdots$2012-04-23
  • 0
    you are right, of course. It was 4 digits i wanted to say2012-04-23
  • 0
    i don't understand your notation, though2012-04-23
  • 11
    @André: What you are doing is not a genuine binary representation of $\pi$. You are just taking the decimal representation and then encoding every digit into binary. I don't know what you want to do with that. Might be exactly what you need for your purposes, but it's not a binary representation of $\pi$. What Jyrki is showing is the true binary representation of $\pi$.2012-04-23
  • 1
    In base 2 $5=101_2$ because $5=1\cdot2^2+0\cdot2^1+1\cdot2^0$. Notice how the exponents indicate the position of the bit. We just continue with negative exponents. For example, $$1011.11_2=2^3+2^1+2^0+2^{-1}+2^{-2}=11\frac34.$$2012-04-23
  • 1
    About the decimal point (which I guess you could call the 'binary point' in base 2): as you can see from the comments and answers, we just represent it the same, and it marks the transition point from non-negative powers of $n$ to negative powers of $n$, for a number written in base $n$.2012-04-23
  • 0
    When you say *back tatoo*, do you really mean [back tatoo](http://www.google.fr/search?q=back+tatoo&um=1&ie=UTF-8&hl=fr&tbm=isch&source=og&sa=N&tab=wi&ei=dJKVT4icFcT50gHXr43nBw&biw=1585&bih=929&sei=eZKVT-CkHcrh0QHz6oTnBw) ?2012-04-23
  • 0
    @Lierre, yes, it is a back tatoo. Not a tramp stamp though :)2012-04-23
  • 1
    @J.M. Why have you removed the (binary) tag? The word binary currently occurs 17 times in the title, the question body, both answers and several comments. If someone searches for (binary)-related questions they may be interested in this one.2012-04-23
  • 0
    @Peter: it's a tad too specific, no? [tag:number-systems] was the umbrella tag for questions like this, As for searching: it will pop up if you input the word binary into the search box, so I don't see the problem you're seeing.2012-04-23
  • 0
    Why not just stick with the decimal version? Few will recognize the binary form.2013-02-12

3 Answers 3

18

What you're suggesting is known as binary coded decimal representation. It is used by some simple calculators, and used to be commonly used in financial computing, because it can represent dollar amounts without rounding the cents (and also makes it easier to produce decimal output for human consumption). But it is harder to calculate with than true binary representation, which for $\pi$ is

11.0010010000111111011010101000100010000101101000110... 

as found here. Here each bit after the point represents successively $1/2$, $1/4$, $1/8$, $1/16$, ..., $2^{-n}$, ..., so according to this representation $$ \pi = 2+1+1/8+1/64+1/2048+1/4096+\cdots$$

In practical computing, irrational numbers are nowadays almost always represented in binary, rounded to a fixed number of significant binary digits and then represented in a binary variant of scientific notation. There's a widely-used standard for how to do this, IEEE-754, which allows different programs or systems to exchange floating-point values without first converting them to decimal notation. (A recent update of the standard defines more format, but is not as widely adopted).

  • 0
    thank you. can you please see my update in the question?2012-04-23
  • 0
    The link Henning included in his answer (the one that says 'here') should give you all the digits you could want!2012-04-23
  • 0
    @André: The link marked "here" gives you 32768 bits. There are probably millions more to find if you google for them.2012-04-23
  • 0
    thank you, that is really what i was looking for2012-04-23
  • 1
    @André: Well, funnily enough that page is the first result when I google 'pi in binary'. Did you not think of trying that?2012-04-23
  • 0
    you are right, but i wouldn't know if it is the most standardized way to represent it. thank you anyway :)´2012-04-23
9

Representing any real number in binary (or any base) is just the same principle as representing numbers in decimal.

For example, in decimal $\frac{25}{8} = 3.125 = 3\cdot 10^0 + 1\cdot 10^{-1} + 2\cdot 10^{-2} + 5\cdot 10^{-3}$.

Now to write the same number in binary, first express it as a sum of powers of $2$ (this is exactly what you do when writing natural numbers in binary):

$\frac{25}{8} = 2 + 1 + \frac{1}{8} = 2\cdot 2^1 + 1\cdot 2^0 + 0\cdot 2^{-1} + 0\cdot 2^{-2} + 1\cdot 2^{-3} = 11.001_2.$

  • 0
    Sorry about the typos. I had a different example at first but then decided to keep it really simple, but then didn't change everything.2012-04-23
  • 0
    thank you. can you please see my update in the question?2012-04-23
1

Any series of bytes can be represented in binary. You might as well encode Pi in bytes first, and then represent those bytes in binary.

If you use a "pure" binary format like described above, you'd need to write "," which is not a valid binary digit.

File formats (series of bytes) are standardized unlike ad-hoc improvisations of binary encoding.

So what I'd suggest is: get hold of the B-file (a standardized format) of OEIS A000796 (B-file available here). Now you have your bytes. Now convert the bytes into an ASCII representation of binary digits.

Python 3:

>>> import urllib.request >>> bin(int.from_bytes(urllib.request.urlopen("http://oeis.org/A000796/b000796.txt").read(),byteorder='big')) 

Beware that the generated string (from bin) will start 0b.