void sum_add(ulong*sum, const char* str)
{
size_t len = strlen(str);
for (size_t i=0; i
This is what I did:
proc sum_add {sum str} {
set len [string length $str]
for {set i 0} {$i < $len} {incr i} {
set sum 0
set sum [expr ($sum + ([scan [string index $str $i] %c] * (($i + 1) << 4))) % 0x10000]
}
return $sum
}
ulong is a 32-bit unsigned integer
The correct result is: [sum_add 0 “Dr.X”] = 0x00003120
But I got [sum_add 0 “Dr.X”] = 5632
Why? I guess the scan has problem but I don’t know how to fix it.
Can anyone help? Thanks!
Sam