1
$\begingroup$

I have a bunch of numbers that I want to print in hexadecimal form using exactly 16 symbols, padded left with zeros if needed. For example, if $x=255$, I want to get $f[x]="00000000000000FF"$ or $f[x]="0x00000000000000FF"$. I tried BaseForm and NumberForm but didn't quite get it.

Any help is appreciated!

$\endgroup$
3
  • $\begingroup$ Is there a way to do that without reinventing the wheel? $\endgroup$
    – Georgy
    Mar 25, 2023 at 15:17
  • $\begingroup$ I didn't think about IntegerString, thanks! $\endgroup$
    – Georgy
    Mar 25, 2023 at 15:28
  • $\begingroup$ How do I mark this question as answered? $\endgroup$
    – Georgy
    Mar 25, 2023 at 15:38

1 Answer 1

4
$\begingroup$
"Ox" <> IntegerString[255, 16, 32]

"Ox000000000000000000000000000000ff"

$\endgroup$
1
  • $\begingroup$ I can't find a duplicate of the question, so I propose an answer. If someone find a duplicate, inform me. $\endgroup$
    – andre314
    Mar 25, 2023 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.