max and min of 2's complement
pgbpsu
Posts: 460
I'm trying to grab the max and min values (in SPIN) from an array of 24-bit 2's complement data. Any clever suggestions? I'm afraid I need to convert all the data into signed ints, then scan them. Is there a better way, a way to determine this without converting them first?
Thanks,
Peter
Thanks,
Peter

Comments
CON tableSize = 32 VAR long theMax, theMin, table[noparse][[/noparse]tableSize] PRI findMinMax | i, temp theMin := POSX ' Anything is lower than this theMax := NEGX ' Anything is higher than this repeat i from 0 to tableSize-1 ' Go through the table temp := (table[noparse][[/noparse] i ] << 8) ~> 8 ' Convert to signed long theMin <#= temp ' Find the minimum value in the table theMax #>= temp ' Find the maximum value in the table-Phil
Thank you both for the prompt and useful suggestions. I should have know shifting was required because my sign bit isn't in bit 31. I think either one of these solutions will work quite well.
Thanks,
Peter