You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Formatting any slice (or array) but []byte in binary using the %b format code works. For example:
fmt.Printf("%d", []int{1,2,3}) -> [ 1 10 11 ]
but if the members of the array or slice are byte then the special case fmtBytes() is invoked, and it lacks a %b case. So instead the formatting fails:
Looking at the code in src/fmt/ I don't think it would be hard to not only make %b work on []byte, but to also make it work nicely, like %x and % x do, giving something like:
Formatting any slice (or array) but []byte in binary using the %b format code works. For example:
fmt.Printf("%d", []int{1,2,3}) -> [ 1 10 11 ]
but if the members of the array or slice are byte then the special case fmtBytes() is invoked, and it lacks a %b case. So instead the formatting fails:
fmt.Printf("%b", []byte{1,2,3}) -> %!b([]uint8=[1 2 3])
Looking at the code in src/fmt/ I don't think it would be hard to not only make %b work on []byte, but to also make it work nicely, like %x and % x do, giving something like:
fmt.Printf("% b", []byte{1,2,3}) -> 00000001 00000010 00000011
which is the binary equivalent of the special case % x operation on a []byte, which, for reference, produces:
fmt.Printf("% x", []byte{1,2,3}) -> 01 02 03
I see this behavior in go 1.5.1 on linux/amd64 and linux/arm, but the behavior isn't new, nor is it specific to those OS/ARCH combinations.
The text was updated successfully, but these errors were encountered: