How to Convert Numbers to Binary or Hex with BASE
BASE converts numbers to binary, hexadecimal or any base up to 36 — and pads them, perfect for building hex colour codes.
You will learn to
- Convert a number to binary
- Convert a number to padded hexadecimal
- Build a #RRGGBB colour code from RGB values
How it works
BASE(number, radix, [min_length]) converts a non-negative whole number into text in another base: =BASE(255,2) is 11111111 and =BASE(255,16) is FF. The radix can be anything from 2 to 36, so it also handles octal (8) and compact base-36 codes.
The optional min_length pads the result with leading zeros, which matters whenever fixed-width codes are expected. Web colours are the classic example: each of red, green and blue becomes two hex digits, so ="#"&BASE(R,16,2)&BASE(G,16,2)&BASE(B,16,2) builds a code like #708090. Use DECIMAL to convert back.
=BASE(B3,16,2)