Integer & floating-point numbers to binary
Encode and decode between numbers and binary strings using (un)signed integer or IEEE 754 floating-point formats.
This article is a work in progress.
Numeric data formats
Unsigned integer
The unsigned integer data format can represent exact positive natural numbers between 0 and an upper bound depending on a given size.
Available sizes: 8-bit, 16-bit, 32-bit, 64-bit
Signed integer
The signed integer data format can represent exact positive and negative natural numbers between a lower bound and an upper bound depending on a given size. The first bit is used to determine whether the number is positive (0) or negative (1). The remaining bits encode the number itself.
Available sizes: 8-bit, 16-bit, 32-bit, 64-bit
IEEE 754 Floating-point
Available sizes: Single-precision (32 bit), Double-precision (64 bit)
Resources
- Integer (computer science) on Wikipedia
- IEEE Standard for Floating-Point Arithmetic on Wikipedia
- Number encoder source code on GitHub