I'm working with a range of 0 to 255.
My data would be a set of numbers within this range.
Except I need the difference between
255 & 0 = 1
254 & 5 = 7
So in a sense this range is a circular set, and 255 and 0 are the p开发者_如何学Cole.
Is there some function / easy way to do this? Or do I need to take the second half of the range and assign it some value to be calculated against? i.e. 255 becomes 255 - 254 if it is being compared against [1 - 127.4]
def diff256(a, b):
return min((a - b) % 256, (b - a) % 256)
精彩评论