Posted to tcl by karen at Sun Jan 31 19:34:55 GMT 2021view raw

  1. #helper func: converts decimal input to binary output
  2.  
  3. proc dec2bin i {
  4. #returns a string, e.g. dec2bin 10 => 1010
  5. set res {}
  6. while {$i>0} {
  7. set res [expr {$i%2}]$res
  8. set i [expr {$i/2}]
  9. }
  10. if {$res == {}} {set res 0}
  11. return $res
  12. }