Scripting equivalent to binEnc()

Is there an equivalent to binEnc() in the scripting environment?

No, but you can use the following function:[code]def binEnc(args):
value = 0
for i in range(len(args)):
if args[i]:
value |= 1 << i
return value

print binEnc([1, 0, 1, 0, 1])[/code]

Travis posted before I got mine, which was really close! :laughing:

Variation on a theme…

[code]def binEnc(*args):
value = 0
for i in range(len(args)):
if args[i]:
value |= 1 << i
return value

print binEnc(1, 0, 1, 0, 1)[/code]

The only difference is that with *args, making a list is not needed. Both have their uses, since you may find it better to create a list via some other routine and binEnc that. If it’s something that stays static, then the second one may be okay for you.

I’ll test these out. Thanks guys.