Re: Quick way to convert Integers to Binary in TCL
- From: suchenwi <richard.suchenwirth-bauersachs@xxxxxxxxxxx>
- Date: Mon, 30 Jul 2007 01:04:27 -0700
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}
}
.
- References:
- Quick way to convert Integers to Binary in TCL
- From: Mahurshi Akilla
- Quick way to convert Integers to Binary in TCL
- Prev by Date: Re: Quick way to convert Integers to Binary in TCL
- Next by Date: Re: Win32 serial port access (don't forget flow control!)
- Previous by thread: Re: Quick way to convert Integers to Binary in TCL
- Next by thread: Re: Quick way to convert Integers to Binary in TCL
- Index(es):