Template:Hexdigits2
Jump to navigation
Jump to search
23
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
- Usage: {{hexdigits2|254}}Template:Nsgives: FE
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
- Template:Hexadecimal - change any number into hexadecimal (1 to many digits)
The above documentation is transcluded from Template:Hexdigits2/doc. (edit | history) Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages. Please add categories to the /doc subpage. Subpages of this template. |