1 and 1 = 1
1 and 0 = 0
0 and 0 = 0
The way larger numbers are store depends on the position of the 1:2 = binary(10)
3 = binary(11)
4 = binary(100)
5 = binary(101)
6 = binary(110)
7 = binary(111)
8 = binary(1000)
And so on. So you see a new position is opened for each power of 2. Same as a new position is opened in decimal numbers for each power of 10.You can use boole (http://docs.autodesk.com/ACD/2013/DEU/index.html?url=files/GUID-C8412B41-BED9-4182-94E6-9EDB3C176D13.htm,topicNumber=d30e603676) yes.
I need to know if any of the object snap is set to on ( active )
(setq osm (getvar "osmode"))
I get this value 4119 , how can I know if the nearest or insertion modes are set on with that return value ? and how to add it to the How can I know if the nearest or insertion modes are set on with that return value ? and how to add it to the new settings of the current osmode value and after the routine finishes , I need to reset them back as they were before these changes .
How can I know if the nearest or insertion modes are set on with that return value ? and how to add it to the new settings of the current osmode value and after the routine finishes , I need to reset them back as they were before these changes .
I would recommend:Code - Auto/Visual Lisp: [Select]
=======================================
bit: 7 6 5 4 3 2 1 0
---------------------------------------
dec: 128 64 32 16 8 4 2 1
=======================================
155: 1 0 0 1 1 0 1 1
=======================================
bit: 7 6 5 4 3 2 1 0
---------------------------------------
dec: 128 64 32 16 8 4 2 1
=======================================
155: 1 0 0 1 1 0 1 1 = 155
---------------------------------------
72: 0 1 0 0 1 0 0 0 = 72
=======================================
LOGIOR: 1 1 0 1 1 0 1 1 = 219
; =========================================================================================== ;
; Lista bitow liczby calkowitej / List of bits integer ;
; Number [INT] - liczba calkowita / integer number ;
; ------------------------------------------------------------------------------------------- ;
; (cd:CAL_BitList 127) ;
; =========================================================================================== ;
(defun cd:CAL_BitList (Number / n res)
(setq n 1)
(while (>= Number n)
(and
(= (logand Number n) n)
(setq res (cons n res))
)
(setq n (lsh n 1))
)
(if res
(reverse res)
(list Number)
)
)
(cd:CAL_BitList 4119) -> (1 2 4 16 4096)
?(defun bits ( n / b )
(if (< 0 n)
(cons (setq b (expt 2 (fix (/ (log n) (log 2))))) (bits (- n b)))
)
)
_$ (bits 4119)
(4096 16 4 2 1)
(defun bits ( n / b l )
(repeat (1+ (setq b (fix (/ (log n) (log 2)))))
(if (= 1 (rem (lsh n (- b)) 2))
(setq l (cons (lsh 1 b) l))
)
(setq b (1- b))
)
l
)
_$ (bits 4119)
(1 2 4 16 4096)
(defun dec->bin ( n / b l )
(repeat (1+ (setq b (fix (/ (log n) (log 2)))))
(setq l (cons (rem (lsh n (- b)) 2) l)
b (1- b)
)
)
(reverse l)
)
_$ (dec->bin 4119)
(1 0 0 0 0 0 0 0 1 0 1 1 1)
; Function: ALE_UtlBits_AreOn
;
; Version 1.00 - 16/11/2006
;
; Arguments:
; BtsVal = Integer [INT]
; IntNum = Integer [INT]
;
; Return Values:
; T if all bits <BtsVal> in number <IntNum> are set
;
; Example:
; (if (ALE_UtlBits_AreOn 2 18) (progn (princ "\nBit 2 is set in 18") (princ)))
;
(defun ALE_UtlBits_AreOn (BtsVal IntNum)
(and
(eq (type BtsVal) 'INT)
(eq (type IntNum) 'INT)
(eq BtsVal (logand IntNum BtsVal))
)
)
;
; Function: ALE_UtlBits_GetBitWise
;
; Version 1.00 - 16/11/2006
;
; Arguments:
; BtsVal = Integer [INT]
;
; Return Values:
; [LIST] a list of all logical bitwise AND's of an integer
; or nil if BtsVal > 32767 or < 1
;
; Examples:
; (ALE_UtlBits_GetBitWise 32767)
; ==> (1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384)
; (ALE_UtlBits_GetBitWise 32768)
; ==> nil
; (ALE_UtlBits_GetBitWise nil)
; ==> nil
; (ALE_UtlBits_GetBitWise 0)
; ==> nil
;
(defun ALE_UtlBits_GetBitWise (BtsVal / CurBit OutVal)
(cond
( (> 1 BtsVal 32767) nil ) ; 32767 = bits sum max value
( (setq CurBit 1)
(while (<= CurBit BtsVal)
(if (= (logand BtsVal CurBit) CurBit)
(setq OutVal (cons CurBit OutVal))
)
(setq CurBit (* CurBit 2))
)
(reverse OutVal)
)
)
)
_$ (list-bits 123456)
((6 . 64) (9 . 512) (13 . 8192) (14 . 16384) (15 . 32768) (16 . 65536))
See this thread also:
http://www.theswamp.org/index.php?topic=12786 (http://www.theswamp.org/index.php?topic=12786)
In the same vein, this digression may also be of interest:
http://www.cadtutor.net/forum/showthread.php?61237-I-want-just-Blocks-and-not-Xrefs&p=416106&viewfull=1#post416106 (http://www.cadtutor.net/forum/showthread.php?61237-I-want-just-Blocks-and-not-Xrefs&p=416106&viewfull=1#post416106)