I would like to use bit flags in some my code but I have no idea how to figure out how to determine what bit flags are being used. Ex. 2 = A 4 = B 8 = C 16 = D 32 = E ------------------- 50 = A D E In code whats the easiest way to know that 50 = 2, 16, & 32. Any one out there now of a good place to get help/info on this topic? Thanks, Shane
Maybe (logand) might help... (defun interpret (code / rosetta answer) (setq rosetta '((1 "-")(2 "A")(4 "B")(8 "C")(16 "D")(32 "E"))) (setq answer "") (foreach stone rosetta (if (= (logand code (car stone))(car stone)) (setq answer (strcat answer (cadr stone))) ) ) answer ) Command: (interpret 50) "ADE" Command: (interpret 51) "-ADE" Of course you can control the order of characters only by changing the rosetta list. out how to determine what bit flags are being used.
Hi Shane-W This will do the job: Code: ; ; -- Function MeGetBitwise ; Returns a list of all logical bitwise AND's of an integer. ; Copyright: ; ©1998 MENZI ENGINEERING GmbH, Switzerland ; Arguments [Typ]: ; Val = Value [INT] ; Return [Typ]: ; > List of logical bitwise AND's [LIST] ; Notes: ; None ; (defun MeGetBitwise (Val / CurBit RetVal) (setq CurBit 1) (while (<= CurBit Val) (if (= (logand Val CurBit) CurBit) (setq RetVal (cons CurBit RetVal)) ) (setq CurBit (* CurBit 2)) ) (reverse RetVal) ) _$ (MeGetBitwise 50) (2 16 32) Cheers
Shane, A while back asked for some help on LOGAND (the function you'll need). Devin posted an EXCELLENT tutorial on using bits. I also posted a follow up question and you might be interested in those responses as well. Watch out for the word wrap and note that the asterisk at the end IS part of the URL. The original question: http://groups.google.com/groups?hl=...=logand&safe=images&as_uauthors=rdi&lr=&hl=en The Follow Up Question: http://groups.google.com/groups?hl=...meta=group%3Dautodesk.autocad.customization.* Also a google search on LOGAND in the customization NG: http://groups.google.com/groups?hl=en&lr=&q=logand&meta=group=autodesk.autocad.customization.* HTH