Difference between revisions of "Hex"

From Sega Retro

 
Line 1: Line 1:
 
<includeonly>{{#vardefine:hexoutput|{{#replace:{{#replace:{{uc:{{{1|}}}}}|$|}}|0X|}}}}{{
 
<includeonly>{{#vardefine:hexoutput|{{#replace:{{#replace:{{uc:{{{1|}}}}}|$|}}|0X|}}}}{{
#vardefine:i|0}}
+
#vardefine:i|0}}{{#while:
{{#while:
 
 
| {{#ifeq:{{#pos:{{#var:hexoutput}}|0}}|0|true}}
 
| {{#ifeq:{{#pos:{{#var:hexoutput}}|0}}|0|true}}
 
| {{#vardefine:hexoutput|{{#sub:{{#var:hexoutput}}|1}}}}{{incvar|i}}
 
| {{#vardefine:hexoutput|{{#sub:{{#var:hexoutput}}|1}}}}{{incvar|i}}
Line 18: Line 17:
  
 
<tt><nowiki>{{hex|$00}}</nowiki></tt> returns {{hex|$00}}.
 
<tt><nowiki>{{hex|$00}}</nowiki></tt> returns {{hex|$00}}.
 
  
 
[[Category:Templates]]</noinclude>
 
[[Category:Templates]]</noinclude>

Latest revision as of 16:46, 24 April 2023

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.