About this tool
Binary strings, sequences of 0s and 1s, are handy for teaching number systems, testing parsers and bit-manipulation code, creating bit masks and flags, and filling binary fields with sample data. This generator produces them at any length up to 1024 bits, grouped the way you read them.
Every value comes from crypto.getRandomValues(), your browser’s cryptographically secure random number generator, never Math.random(), and nothing is sent to a server.
How to use it
- Set the number of bits: 8 for a byte, 32 for a typical integer, 64 for a long.
- Group them in 4 bits (one hex digit, a “nibble”) or 8 bits (one byte) for readability.
- Add 0b to paste them into code: JavaScript, Python, Java, C# and C++14 all accept binary literals like
0b1011.
Each bit is 0 or 1 with exactly equal probability. For up to 53 bits, the line under the button shows the range of values the strings can represent.
Binary, hex and decimal
Every 4 bits map to one hex digit: 1010 1111 is AF in hex and 175 in decimal. In code, parseInt('10101111', 2) in JavaScript or int('10101111', 2) in Python gives the number. For long random values, hex is more compact: use the Random Hex Generator.
FAQ
How do I generate a random binary number?
Choose how many bits you want and click Generate. Each bit is 0 or 1 with equal probability.
How do I convert binary to decimal?
Use parseInt(binary, 2) in JavaScript or int(binary, 2) in Python. For example, 1011 is 11.
What does 0b mean?
It marks a binary literal in code, as in 0b1011 for eleven. Turn on the 0b prefix to add it.
Is each bit equally likely?
Yes. Bits come from the browser’s cryptographically secure random number generator.