Subject: | |
From: | |
Reply To: | |
Date: | Fri, 17 Nov 2000 12:03:08 -0800 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
At 2:34 PM -0500 11/17/00, Russ Smith wrote:
>Does anyone have or know of a program/process/command file to quickly
>convert back and forth between integer values and the string version of
>their bit equivalent?
>
>For example:
>
> XEQ INT2BIT 14
> returns 00001110
>
> SETVAR INBIT;"00001110"
> XEQ BIT2INT !INBIT
> returns 14
>
>Okay, the second one is a piece of cake, but how about the first?
Actually, the first is a piece of cake, too:
:print num2bin
parm innum=0
setvar tnum !innum
setvar binval ""
while tnum > 0
setvar bit tnum mod 2
setvar binval "!bit" + binval
setvar tnum tnum/2
endwhile
echo !binval
:
:num2bin 14
1110
:num2bin 48
110000
:num2bin 96
1100000
:num2bin 63
111111
:
Of course, you'll have to add extra stuff to verify that the parmeter is
numeric, and perhaps check that it's within the range of allowable
integers, etc..., but that's left as an exercise for the user. Enjoy!
Barry Lake [log in to unmask]
Allegro Consultants, Inc. www.bogus.allegro.com
(408)252-2330
--------
Attempting to reduce spam influx.
Remove ".bogus" to create valid address.
|
|
|