I am talking about bits because the behavior I want is exactly and specifically to show a fixed-width BinaryInteger
in a given base, with enough digits to represent all of the bits in that number.
I often want this in binary and hexadecimal, but I would also use it in octal and decimal. This is a general-purpose, useful operation.
Literally nobody has asked to sign-extend to a power of 3. We are talking about using the existing in-memory representation of a fixed-width BinaryInteger
, and creating a string to display it in a given base, including all of the bits of the number when we do so.
And yes, I am still talking about bits, because the number is represented as a binary integer, and that is what I want to display, in the base of my choice.
This comes across as quite patronizing and I request that you stop.
It is not a matter of βinventingβ something esoteric. I already explained the definition I want, and I think it is simple, straightforward, and natural. It is a useful operation for displaying raw data in binary or hexadecimal or any other base, making sure that all numbers are shown with the same length.
The padding is the essential part that I am trying to add.
Saying it is βleft as an exercise to the readerβ is extremely dismissive, and if anything it makes my point stronger. The standard library does not currently provide a simple, obvious, easy-to-use solution for padding integers for display.
It requires first converting to a non-padded string, then calculating the number of zeros needed, then creating a string which repeats that number of zeros, and finally combining the two strings.
This is a real shortcoming, and one which I would like to see addressed.