A HEX code is three pairs of hex digits for red, green, and blue, each from 0 to 255. A 3-digit code doubles each digit first. The page then scales those channels to the range 0–1.
Black is the ink all three channels share: K = 1 − the brightest channel. Cyan, magenta, and yellow are what remains after that black is removed. The results are rounded to whole percentages. HSL is calculated from the same red, green, and blue, so hue, saturation, and lightness describe the screen color rather than the ink.
The reverse starts from the four percentages, rebuilds red, green, and blue, and writes them back as HEX. Integer rounding means a round trip can land a step away from the original code.
This is the straightforward sRGB removal formula. A press conversion also accounts for the printer profile, total ink, and the paper. Use these numbers to read and copy a color. Use your printer's workflow when the file is going on press.