-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fmt: differing output of printf %#010x with int and string types #28627
Comments
This seems to be consistent with the documentation (https://godoc.org/fmt):
The difference is that the verb %x applies to each byte in strings and # is an alternate format for the verb so also per byte but the padding is not described to be per byte but applies to the output as a whole. An improvement for the documentation that could be made is for '0': |
But it does not add an '0x' for each byte:
As far as I understood you it should print something like:
|
you are right it i was confusing this with ' ' where it applies per byte and is mentioned explicitly "% x" in documentation. Referring back to the original issue of 0 padding I think its still in line with documentation that padding of 0 applies to the whole string after it has been formatted? Could maybe made explicit. To format the string like the number in the first example you could do: If its not an obvious bug or contradicting documentation its likely not to change how fmt formats this as its established behavior by now that other programs will rely on. |
I cannot find this in the documentation for printf. This is what I've found:
It does only say what happens if you pad it with spaces, so I agree it should be more explicitly stated what happens if you use zeros instead of spaces. |
CC @robpike |
Padding applies to the whole result. |
What did you do?
I wanted print a padded (zeros) and prepended (0x) string character as a hex number.
Link to example on play.golang.org
What did you expect to see?
The same result for a string character and an integer.
The string printed as an hexadecimal number should be prepended with '0x'.
What did you see instead?
System details
The text was updated successfully, but these errors were encountered: