Is there any function or an easy way to “reverse-engineer” a bitmask such as used in Rhino’s object types?
For example take the number 60 and decode it into 4+8+16+32?
Thanks, --Mitch
Is there any function or an easy way to “reverse-engineer” a bitmask such as used in Rhino’s object types?
For example take the number 60 and decode it into 4+8+16+32?
Thanks, --Mitch
I guess I could do it like this:
def DecodeBinaryObjType(number):
bin_str="{0:b}".format(number)
bin_lst=[int(elem) for elem in bin_str]
bin_lst.reverse()
if bin_lst[0]: print "Points present"
if bin_lst[1]: print "PointClouds present"
if bin_lst[2]: print "Curves present"
if bin_lst[3]: print "Surfaces present"
if bin_lst[4]: print "Polysurfaces present"
if bin_lst[5]: print "Meshes present"
#etc.
DecodeBinaryObjType(60)
I slightly misunderstood what you were going for. It can be done neatly using bitmasks and boolean operators, but I thought you were asking for a RhinoScript solution.
Either way, here’s one way to do it in VB:
bitmask.gh (2.9 KB)
OK, thanks anyway for answering David! --Mitch