digitalmars.D.learn - Easy way to format int in pragma msg ?
- wjoe (4/4) May 14 2020 Is there an easy way to print an int in hexadecimal, octal or
- John Chapman (6/10) May 14 2020 import std.string;
- WebFreak001 (7/11) May 14 2020 for simple hex/binary/etc printing use
- wjoe (2/14) May 14 2020 That's great. Thanks for the fast reply. To both of you :)
Is there an easy way to print an int in hexadecimal, octal or binary representation ? The documentation on pragma(msg, ...) and a quick web search didn't provide an answer.
May 14 2020
On Thursday, 14 May 2020 at 09:49:15 UTC, wjoe wrote:Is there an easy way to print an int in hexadecimal, octal or binary representation ? The documentation on pragma(msg, ...) and a quick web search didn't provide an answer.import std.string; pragma(msg, format("%x", 10)); %x = hex %o = octal %b = binary
May 14 2020
On Thursday, 14 May 2020 at 09:49:15 UTC, wjoe wrote:Is there an easy way to print an int in hexadecimal, octal or binary representation ? The documentation on pragma(msg, ...) and a quick web search didn't provide an answer.for simple hex/binary/etc printing use import std.conv; pragma(msg, i.to!string(16)); where you can replace 16 with your target base. You can also use format as in the previous reply if you want more formatting control
May 14 2020
On Thursday, 14 May 2020 at 10:58:34 UTC, WebFreak001 wrote:On Thursday, 14 May 2020 at 09:49:15 UTC, wjoe wrote:That's great. Thanks for the fast reply. To both of you :)Is there an easy way to print an int in hexadecimal, octal or binary representation ? The documentation on pragma(msg, ...) and a quick web search didn't provide an answer.for simple hex/binary/etc printing use import std.conv; pragma(msg, i.to!string(16)); where you can replace 16 with your target base. You can also use format as in the previous reply if you want more formatting control
May 14 2020