-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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 does not format byte slices nicely #34916
Comments
I'm sorry, I don't understand what you are asking for. It seems that using Whatever we think of the behavior of the fmt package (and I think it is making a reasonable choice here) we can't change it now. It would break too many existing programs. |
|
slcByte := [...]byte{10,20,30,40,50,60,70,80,90,100,101} gives output: does this look like expected/reasonable behaviour ? @martisch thanks ! this is exactly what I was looking for ! |
The current behavior looks to me as documented in package fmt. Note that []byte often formats the way a string would be formatted. That is why []int behaves differently. We can not change it without breaking backwards compatibility. Since there is a way to format the slcByte the way wanted I am closing the issue. If the behavior should be changed please open a new issue with a concrete proposal for Go 2 how the behavior of fmt should be changed and how the gained advantage is worth breaking the backwards compatibility. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
reproduces on go playground
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I'm trying to print a slice of bytes as an array of hex values.
What did you expect to see?
[0x0a 0x14 0x1e 0x28 0x32 0x3c 0x46 0x50 0x5a 0x64 0x65]
What did you see instead?
0x0a14
Please see playground link:
https://play.golang.org/p/gQIYJV6ogx4
The first line is ok for a slice of ints.. the %.2v is a sort of workaround, but not what I actually need.
dump from playground:
output:
The text was updated successfully, but these errors were encountered: