Re: Quick way to convert Integers to Binary in TCL




Mahurshi Akilla wrote:
Is there a quick way to convert integers to binary in TCL? (Without
writing our own proc to do this)

None, that I'm aware of (maybe in some of the math-packages?). But
whats wrong with writing an own proc for it, when it is that simple?:

proc toBinaryString {val} {
set result [expr {($val==0)?0:""}]
while { $val != 0 } {
set result "[expr {($val&1)?1:0}]${result}"
set val [expr {$val>>1}]
}
return $result
}

Regards
Stephan

.



Relevant Pages

  • Re: equality and errors
    ... This seems to me like a non-standard use of the catch mechanism. ... you have a proc which validates the contents of two ... If I were writing this program, though, I would use a different approach ... have the calling code respond intelligently to that value, ...
    (comp.lang.tcl)
  • Use "range," not "for"?
    ... Thanks to everyone who suggested ways to get a proc to recognize all ... So, here's my first effort. ... Or, if you have a list called "lum," instead of writing this: ... proc range {var star cutoff fin args} { ...
    (comp.lang.tcl)
  • Re: Use "range," not "for"?
    ... David McClamrock wrote: ... > Instead of writing this: ... It demonstrates an "integer range generator" proc called ... how to neatly handle executing a script body that's passed as an ...
    (comp.lang.tcl)
  • Re: New to MuPad
    ... I am now in the process of writing a ... domain constructor in MuPad, and I can not get the 'new' proc to work. ...
    (sci.math.symbolic)
  • how to check for file exist from inside a stored procedure?
    ... im writing an CF app and using a sybase database. ... proc i want to check to see if a file exist on the device. ...
    (microsoft.public.dotnet.framework.compactframework)