Re: Quick way to convert Integers to Binary in TCL



On 30 Jul., 07:47, Mahurshi Akilla <mahur...@xxxxxxxxx> wrote:
Is there a quick way to convert integers to binary in TCL? (Without
writing our own proc to do this)

Procs are most always good to structure the code. Here is a little one
that packages binary scan/format:

proc dec2bin int {
binary scan [binary format I $int] B* res
set res
}
69 % dec2bin 255
00000000000000000000000011111111

As you see, you get 32 bits back. A variation that suppresses leading
zeroes is
proc dec2bin int {
binary scan [binary format I $int] B* res
if {$res} {string trimleft $res 0} else {set res 0}
}

.