Binary Cheatsheet

I have been using Tcl for years, but I still need to lookup the manual every time I use binary format and binary scan. If you are like me, you will find this cheatsheet a handy reference.

` ` Endian      
Little Big Host Type Notes
a     byte string format pads with nulls
A     byte string format pads with spaces, scan strips trailing spaces/nulls
b B   binary digits  
h H   hex digits  
c     8 bit integer list In other words, ASCII chars
s S t 16 bit integer list  
i I n 32 bit integer list  
w W m 64 bit integer list  
r R f single prec. float list  
q Q d double prec. float list  
x     null bytes count is number of bytes
X     move cursor back count is number of bytes to back up
@     move cursor to location count is byte position, zero based


set bin [binary format I2sH2a* {0x123 0x456} 17 ab "testing"]

# This returns 4 (number of conversions)
binary scan $bin I2sH2a* intlist intval hexval str

Steve Bennett (

comments powered by Disqus