HEX to RGB, px to rem, Unix Time: Developer Conversions

Four conversions cover most of what front-end and back-end work throws at you: colors between hex and RGB, sizes between px and rem, moments in time as Unix seconds, and integers across number bases. All four are exact — no rounding conventions, just positional arithmetic.

ConversionBy Jul 19, 20266 min read
HEX to RGB, px to rem, Unix Time: Developer Conversions — ListCalc

HEX to RGB: one color, two spellings

A hex color like #0E6B54 is just three numbers written in base 16 and glued together. Split it into pairs and convert each pair to decimal:

#0E6B54 → 0E | 6B | 54
0E = 0×16 + 14 = 14   6B = 6×16 + 11 = 107   54 = 5×16 + 4 = 84
= rgb(14, 107, 84)

Each pair runs 00–FF, which is 0–255 in decimal — the full range of one 8-bit channel. Hex digits above 9 are letters: A=10, B=11, C=12, D=13, E=14, F=15. Three-digit shorthand doubles each digit: #f80 means #ff8800 = rgb(255, 136, 0). The HEX to RGB converter goes both directions and handles the shorthand.

px to rem: divide by the root

A rem is a multiple of the root element’s font size, which is 16px in every mainstream browser unless someone changes it. So the conversion is a single division:

pxrem (16px root)Common role
40.25Tight spacing unit
80.5Base spacing unit
120.75Caption text
140.875Secondary text
161Body text
201.25Lead paragraph
241.5H3 / large text
322H2
483H1 / display

The reason to bother: rem respects the user’s browser font-size setting, so text set in rem scales for people who need it larger, while px ignores them. Sizes that shouldn’t scale with text — borders, hairlines — are the legitimate px holdouts. The px to rem converter also handles custom root sizes for the projects that set html { font-size: 62.5% } to make 1rem = 10px.

Unix time: seconds since 1970

A Unix timestamp counts seconds since 00:00:00 UTC on January 1, 1970 — the epoch. It has no time zone, no DST, no calendar quirks; it is a single integer that every system on earth agrees on, which is why databases and APIs store moments this way.

TimestampUTC date & timeNote
01970-01-01 00:00:00The epoch
1,000,000,0002001-09-09 01:46:40The billennium
1,800,000,0002027-01-15 08:00:00Next round milestone
2,147,483,6472038-01-19 03:14:0732-bit signed limit — the Y2038 problem

Two gotchas. JavaScript’s Date.now() returns milliseconds, so its values are 1,000× larger — a 13-digit number is milliseconds, 10 digits is seconds. And the 2038 limit only bites systems still storing time in a signed 32-bit integer; 64-bit timestamps are safe for about 292 billion years. Decode any value with the Unix timestamp converter.

Binary, octal, hex: same number, different base

A base tells you what each digit position is worth. In base 10 the columns are 1, 10, 100…; in base 2 they are 1, 2, 4, 8…; in base 16 they are 1, 16, 256…. The number doesn’t change, only its spelling:

DecimalBinaryOctalHex
10101012A
64100000010040
25511111111377FF
20261111110101037527EA

Hex earns its place because one hex digit is exactly four binary bits — FF is eight 1s — making it a compact, lossless way to write binary. That is the same reason colors, memory addresses and file permissions (octal, three bits per digit) use these bases. Convert anything up to your patience limit with the number base converter.

Run your own numbers

FAQ

How do I convert a hex color to RGB manually?
Split the six digits into three pairs and convert each pair from base 16: multiply the first digit by 16 and add the second, using A=10 through F=15. #6B is 6 × 16 + 11 = 107.
Why is 1rem equal to 16 pixels?
Because every mainstream browser ships with a default root font size of 16px, and rem is defined as a multiple of the root font size. If the user or the stylesheet changes the root size, 1rem changes with it — which is exactly the point.
How can I tell if a Unix timestamp is in seconds or milliseconds?
Count the digits. Current timestamps are 10 digits in seconds and 13 digits in milliseconds. JavaScript's Date.now() gives milliseconds; most Unix tools and APIs use seconds.
What is the Year 2038 problem?
Systems that store Unix time in a signed 32-bit integer overflow at 2,147,483,647 seconds — 03:14:07 UTC on January 19, 2038. Beyond that the value wraps negative, reading as December 1901. Systems using 64-bit time are unaffected.
Why do programmers use hexadecimal instead of binary?
One hex digit represents exactly four binary bits, so hex is a shorthand for binary with a 4× compression and zero information loss. FF is 11111111 — eight bits in two characters.

Sources

Primary references used for the figures and rules on this page.

  1. CSS Values and Units (rem definition) — W3C
  2. Seconds Since the Epoch definition — IEEE / The Open Group (POSIX)