How might I modify Mathematica such that I can get the following functionality when working with HEX values. The odd lines are input and the even output. Red values should be the HEX values.
What would be the most portable and functionally useful way to display all numbers in HEX? I would like to use either Notation, Symbolize, or Interpretation to display the numbers as HEX but allow them to be interpreted as actual numbers internally.
Answer
Here is my first pass at implementing what you describe. If you find that it deviates from your intended behavior let me know and I shall attempt to refine it.
MakeBoxes[foo_, form_] /; format`hex =!= True :=
Block[{format`hex = True}, ToBoxes[foo, form] /. s_String?DigitQ :>
With[{n = FromDigits@s},
InterpretationBox[StyleBox[#, RGBColor[1, 0, 0]], n] &[
"\"" <> IntegerString[n, 16] <> "\""
]
]
]
Now:
Comments
Post a Comment