Visual LISP, AutoLISP and General Customization
cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 

integer into binary

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
330 Views, 5 Replies

integer into binary

i searched my acad 2000 documentation to find a function which converts
an integer into a binary, but i couldnĀ“t find... is there one, or do i
have to program it by my own?
mfg
gert
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous

There isn't a native one, you would have to program your own.

--
Kevin Nehls


"DI Klaus Umlauf" wrote in message
news:3D4FDEC2.273DEC86@utanet.at...
> i searched my acad 2000 documentation to find a function which converts
> an integer into a binary, but i couldnĀ“t find... is there one, or do i
> have to program it by my own?
> mfg
> gert
>
Message 3 of 6
Anonymous
in reply to: Anonymous

I don;t think there is 1 included.

This is a very old 1 I wrote long ago. Returns STR value

;;;Convert Integer To Bit String - 1s & 0s
;;;ARG -> INT to convert
;;; INT of length to return

(defun ItoB (int bitlen / mod power rpt) ;Define Int To Bit
(setq retbit "" ;Reset Bit String
power (abs 0) ;Reset Power
mod int) ;Set Divisor To Input
(while (>= mod 1) ;While The Remainder Of
(setq mod (/ mod 2)) ;Division Of The Remainder
(setq power (1+ power))) ;By 2 Is Greater Than 1
(setq rpt power) ;Increase The Power By 1
(repeat rpt ;Repeat Power Times
(if (>= int (expt 2 (1- power))) ;If The Integer
(progn ;> 2 To The Power -1
(setq retbit (strcat retbit "1")) ;Set The Bit To 1 Then
(setq int (- int (expt 2 (1- power))))) ;Decrease By 1 Power
(setq retbit (strcat retbit "0"))) ;Else Set The Bit To 0
(setq power (1- power))) ;Decrease The Power By 1
(while (< (strlen retbit) bitlen) ;Add 0's To Match BitLen
(setq retbit (strcat "0" retbit))) ;Returns The String
(setq retbit retbit)) ;And End


"DI Klaus Umlauf" wrote in message news:3D4FDEC2.273DEC86@utanet.at...
> i searched my acad 2000 documentation to find a function which converts
> an integer into a binary, but i couldnĀ“t find... is there one, or do i
> have to program it by my own?
> mfg
> gert
>
Message 4 of 6
Anonymous
in reply to: Anonymous

thank you a lot, you saved me hours...

mfg
gert

David Bethel wrote:

> I don;t think there is 1 included.
>
> This is a very old 1 I wrote long ago. Returns STR value
>
> ;;;Convert Integer To Bit String - 1s & 0s
> ;;;ARG -> INT to convert
> ;;; INT of length to return
>
> (defun ItoB (int bitlen / mod power rpt) ;Define Int To Bit
> (setq retbit "" ;Reset Bit String
> power (abs 0) ;Reset Power
> mod int) ;Set Divisor To Input
> (while (>= mod 1) ;While The Remainder Of
> (setq mod (/ mod 2)) ;Division Of The Remainder
> (setq power (1+ power))) ;By 2 Is Greater Than 1
> (setq rpt power) ;Increase The Power By 1
> (repeat rpt ;Repeat Power Times
> (if (>= int (expt 2 (1- power))) ;If The Integer
> (progn ;> 2 To The Power -1
> (setq retbit (strcat retbit "1")) ;Set The Bit To 1 Then
> (setq int (- int (expt 2 (1- power))))) ;Decrease By 1 Power
> (setq retbit (strcat retbit "0"))) ;Else Set The Bit To 0
> (setq power (1- power))) ;Decrease The Power By 1
> (while (< (strlen retbit) bitlen) ;Add 0's To Match BitLen
> (setq retbit (strcat "0" retbit))) ;Returns The String
> (setq retbit retbit)) ;And End
>
> "DI Klaus Umlauf" wrote in message news:3D4FDEC2.273DEC86@utanet.at...
> > i searched my acad 2000 documentation to find a function which converts
> > an integer into a binary, but i couldnĀ“t find... is there one, or do i
> > have to program it by my own?
> > mfg
> > gert
> >
Message 4 of 6
Anonymous
in reply to: Anonymous

just curious, what is the application for this? ie in what situation do you
need the binary representation of an integer?
Message 6 of 6
Anonymous
in reply to: Anonymous

quick method to check if eg. endpoint is set in sysvar "OSMODE"....

Mark Propst wrote:

> just curious, what is the application for this? ie in what situation do you
> need the binary representation of an integer?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

ā€Boost