HexPi: Value of π in Hexadecimal

Quick Download

Download here. Support This Project Please support us in any amount you can.

What is HexPi?

HexPi (pronounced hex-pie) is a combination of three sub-projects.

  1. It lists first 62,500 and 1,000,000 digits of the numerical constant π in hexadecimal. You can simply download the lists for any purpose you may have and use them.
  2. It provides a C program, aptly named pi-in-hex.c, and a build system to go with it, that let's you generate as many number of digits of π as you like if you have custom need.
  3. It is also a webservice that provides arbitrary number of hexadecimal digits of π in hexadecimal starting from an arbitrary location. The source code for this webservice is part of the open source code in the project.
See below for detailed description of each of these.

Detailed Description

List of hexadecimal value of π

There are two text files given under data directory. The first one is called pi-hex.62500.txt and contains first 62500 hexadecimal values of π. The second one is called pi-hex.1000000.txt and contains first 1 million of the hex digits.

Why two files? These files are intended to be used by programs and if a program does not need beyond 62500 digits, there is no need to load a larger file.

A C program to generate in Hex

This program code/pi-in-hex.c contains minor improvements over the program piqpr8.c by David H Bailey and uses the same BBP algorithm. The improvements include:

  1. Facility to specify the starting decimal position from where the value of π will be printed. This can be specified by the command line argument --start or -s. The argument indicates the position after which the hex digits are printed. For example, if -s 9 is passed, then the value of π will be printed from position 10. The default is 0.
  2. Facility to specify the number of hexadecimal digits that will be printed. It can be done using command line argument --nHexDigits or -n. The default is 10 (decimal).
  3. Facility to output the verbose debug message using --verbose or -v.
  4. Facility to print the help message using the command line argument --help or -h.
Known limitation: The value of n should be multiple of 10.

A webservice

A webservice has been created (using PHP backbone) that can be called as follows:

With no s or n specified, the default value of s is randomized and n is set to 10.

It outputs an XML with the following format.

Known limitation: The value of n should be multiple of 10.
Known limitation: In order to protect the generousity of SourceForge from abuse, the mazximum value of n has been kept as 1000. A larger value of n will be treated as if n is set as 1000.

Hidden agenda behind this project

Since π is an irrational number (meaning its digits never repeat itself), can successive sets of n such digits be grouped together and used as a series of random numbers? This is the primary motivation behind this project. Although I came up with this idea independently, upon further research, it turned out this idea is not unique. As a matter of fact, Blowfish, a cryptographic alorithm, uses few sets of values of π. Also, NIST lists various tests for validating the randomness of its digits.

Although the value of π can be used for any reason, the main objective of this webservice is to provide the hexadecimal digits that can be used as random numbers with subsequent calls. All that a user really need to do is to call it with s=s1, n=n1 one time and then call it again s=s1+n1 and n=n1 the next time.

Project Details


This project is distributed as an open source repository under Lesser GNU Public License (LGPL).

Download source

You can download sources in tar+gzipped from here. Use 'tar -zxvf ...' command to ungzip and untar.


The code for pi-in-hex.c is written (obviously) using ANSI-C. It is tested with gcc 4.4.7 20120313 (on Red Hat 4.4.7-3)

The webservice is written in PHP and is tested using PHP version PHP 5.3.3.

Directory structure of the downloaded tree

Once uncompressed, the downloaded source will create a directory named hexpi. It will also create the following subdirectories under this directory.

  1. doc: Documentation directory.
    • index.html: this file.
    • style.css: CSS stylesheet for this file.
  2. code: Home of the C code.
    • pi-in-hex.c: C program as described above.
  3. data:
    • pi-hex.62500.txt: 62500 hex digits of π after decimal.
    • pi-hex.1000000.txt: 1000000 hex digits of π after decimal.
  4. build:
    • Makefile: for building the binary.

Bug Reporting

Bugs can be reported here.

Your Generous Donation is Much Appreciated

While downloading this program is and will be always free, your donation is always appreciated. The suggested amount is $20, but any amount that you can afford will be gladly accepted. Please click on the icon below to donate.

Support This Project


Swapnajit Mitra is the author and maintainer of this project.