HP3000-L Archives

November 2000, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Barry Lake <[log in to unmask]>
Reply To:
Barry Lake <[log in to unmask]>
Date:
Fri, 17 Nov 2000 12:03:08 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (56 lines)
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.

ATOM RSS1 RSS2