Actions

Template

Difference between revisions of "Hex"

From NEC Retro

(Created page with "<includeonly><tt><b>{{{1}}}</b></tt></includeonly><noinclude> This template displays a hexadecimal value with the appropriate formatting. ==Example== <tt><nowiki>{{hex|0123}}...")
 
 
Line 1: Line 1:
<includeonly><tt><b>{{{1}}}</b></tt></includeonly><noinclude>
+
<includeonly>{{#vardefine:hexoutput|{{#replace:{{#replace:{{uc:{{{1|}}}}}|$|}}|0X|}}}}{{
 +
#vardefine:i|0}}{{#while:
 +
| {{#ifeq:{{#pos:{{#var:hexoutput}}|0}}|0|true}}
 +
| {{#vardefine:hexoutput|{{#sub:{{#var:hexoutput}}|1}}}}{{incvar|i}}
 +
}}{{
 +
#ifexpr:{{#len:{{#var:hexoutput}}}}>4|{{#vardefine:pad|8}}}}{{#ifeq:{{#len:{{#var:hexoutput}}}}|0|{{#vardefine:hexoutput|0}}}}{{RolloverText|1=<span style="font-family: monospace !important; font-weight:bold;"><span style="color:#999999; font-family: monospace !important;">{{padleft:|{{#expr:{{#var:pad}}-{{#len:{{#var:hexoutput}}}}}}|0}}</span>{{#var:hexoutput}}</span>|2=Hexadecimal}}{{clearvar|hexoutput|pad}}</includeonly><noinclude>{{SegaRetroTemplate}}
 
This template displays a hexadecimal value with the appropriate formatting.
 
This template displays a hexadecimal value with the appropriate formatting.
  
Line 8: Line 13:
  
 
<tt><nowiki>{{hex|0x1800}}</nowiki></tt> returns {{hex|0x1800}}.
 
<tt><nowiki>{{hex|0x1800}}</nowiki></tt> returns {{hex|0x1800}}.
 +
 +
<tt><nowiki>{{hex|abcde}}</nowiki></tt> returns {{hex|abcde}}.
 +
 +
<tt><nowiki>{{hex|$00}}</nowiki></tt> returns {{hex|$00}}.
  
 
[[Category:Templates]]</noinclude>
 
[[Category:Templates]]</noinclude>

Latest revision as of 12:04, 22 July 2024

Segaretro-round.svg This template has been manually copied from Sega Retro, specifically Template:Hex
Technical restrictions prevent this template from being shared across multiple wikis. In the medium term, any changes should be made to the Sega Retro variant first, before manually copying the contents back here. As this is not an automatic process, this version of the template might also be out of date.

This template displays a hexadecimal value with the appropriate formatting.

Example

{{hex|0123}} returns 123.

{{hex|$78000}} returns 00078000.

{{hex|0x1800}} returns 1800.

{{hex|abcde}} returns 000ABCDE.

{{hex|$00}} returns 0.