« AUGI releases June issue of HotNews | Main | Using the new Layer Filter interface in AutoCAD 2005 »

Comments

Itlan

Great function. Haven't had the time to figure this one out, so glad I found your blog. I modified your code to work with all types of bitcode variables... had to add a ON/OFF switch for the case when you just want it On, not toggled.

(defun BITCODE (value bit on)
;; Written by Lee Ambrosius
;; Created on: 6/6/04
;; Command toggles the bit of the value (typical used for OSMODE)
;; Value of 'on' determines if bit is to be on (1), off (-1), or toggled (0 or nil)
(cond
((= on "1")(+ value bit))
((= on "-1")(- value bit))
(T
(if (zerop (logand bit value))
(+ value bit)
(- value bit)
)))
)

Jim

Lee, your lisp routine is great. However, it does not take into account the fact that the Bit may already be set. I have modified your code slightly to check this first...


(defun bitcode (value bit on)
;; Written by Lee Ambrosius on: 6/6/04
;; Command toggles the bit of the value (typically used for OSMODE)
;; Value of 'on' determines if bit is to be on (1), off (-1), or toggled (0 or nil)
(cond
((or(= on "1")(= on 1))(if(zerop(logand bit value))(+ value bit)value));; Turn bit on if not already on
((or(= on "-1")(= on -1))(if(not(zerop(logand bit value)))(- value bit)value));; Turn bit of if not already off
(T(if(zerop(logand bit value))(+ value bit)(- value bit);; Toggle bit
)))
) ;defun bitcode

The comments to this entry are closed.

My Photo

My Other Accounts

Twitter Updates

    follow me on Twitter