Cosa icon indicating copy to clipboard operation
Cosa copied to clipboard

IOStream: Cannot print non-dec base without prefix

Open jeditekunum opened this issue 6 years ago • 1 comments

I would like to print out an ethernet MAC address. There appears to be no direct way to do this with IOStream as anything with a hex format is prefixed with "0x". There being 6 bytes to a MAC address I get something like 0xde:0xad:0xbe:0xef:0xfe:0xed when I would rather see de:ad:be:ef:fe:ed.

I could make the enhancement and submit a PR but I would like to get agreement on the approach first. I also just noticed that printf is similar but not the same as standard C printf in its format.

One option would be to add an optional argument to bin(), oct(), hex() to indicate exclusion of the prefix (setting a protected variable). Some additional special character to the format string would need to be added to also manipulate this. Or perhaps just the format could be enhanced without affecting bin()/oct()/hex().

Any recommendations?

jeditekunum avatar Oct 16 '17 16:10 jeditekunum

I just discovered INET::print_mac so that solves my specific issue.

The general issue of printing without prefix remains.

jeditekunum avatar Oct 16 '17 16:10 jeditekunum