Reply To: Need Tcl help: Convert to ulong

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Need Tcl help: Convert to ulong Reply To: Need Tcl help: Convert to ulong

#58829
John Mercogliano
Participant

    Code:


    proc sum_add {sum str} {
      set len [string length $str]
      for {set i 0} {$i < $len} {incr i} {      set char [string index $str $i]      set char [scan $char %c]      set sum [format 0x%08x [expr ($sum + ($char * (($i + 1) << 4))) % 0x10000]]   }   return $sum }

    Notice I removed the if statement? Did you try it this way?  Looking at your C code, the if logic is not needed as even if the string contains a number the C code was still using the ascii equivalent in its calculations not the actual number.  So for example “1065507963”, char would be equal to 42 not 1, 48 not 0…etc

    Hope this helps.

    John Mercogliano
    Semi Retired, contractor
    Hampton Roads, VA