Template:Hexdigits2

From blackwiki
Jump to navigation Jump to search

23

Template documentation[view] [edit] [history] [purge]

The Template:Hexdigits2 shows the 2-digit hexadecimal equivalent of a number from 0-255, ranging from "00" to "FF". It is intended, primarily, to encode hex color codes for the RGB color model (red/green/blue levels), such as with a span-tag: <span style="background:#D2D2D2; color:#4C01FF">.

Usage:    {{hexdigits2|254}}Template:Nsgives: FE
{{hexdigits2|240}}Template:Nsgives: F0
{{hexdigits2|11}}Template:Nsgives: 0B

Performance considerations

To streamline operation, the template uses a rapid binary tree to decide which hexadecimal digits match the value of the base ten number, rather than use #switch functions with more comparisons. The algorithm allows the template to execute at over 350 numbers per second, but only as 2-digit hex values. Larger numbers > 255 will be truncated to 2 digits, in the range F0 to FF, with the last digit modulo 16.

See also