SlickRCBD asked:
>I remember seeing an AppleSoft program that would accept a decimal input
>and convert the number to hex and binary.
>
>While writing it wouldn't be all that difficult, and probably only take me
>an hour or two, I'm wondering if there is a nicer program written in
>AppleSoft already on the web. That is, nicer than what I would make for my
>own usage. I think the program I remember might have been in a Nibble
>disk, but I have no idea what volume, and I don't rememebr which archive
>has it.
>
>I mostly want an AppleSoft implimentation so I can both use the program,
>and rip the code for my own usage in making a little assistant while I
>program on my Mac, which is located about 3 feet away from the IIGS with
>my ImageWrite II in between.
The basic (both senses) routine is:
100 REM N = positive integer to be converted to hex
110 hx$ = ""
120 nn = int(n/16)
130 h = n - nn*16
140 n = nn
150 hx$ = mid("0123456789ABCDEF",h,1) + hx$
160 if n>0 goto 120
170 print hx$
This can be easily adapted for any other radix, including binary, by
changing "16" to the desired radix and shortening or lenghtening the
digit translation string in line 150.
-michael
Check out 8-bit Apple sound that will amaze you on my
Home page: http://members.aol.com/MJMahon/
In article <20020816170101.25039.00001067@mb-md.aol.com>, mjmahon@aol.com
(Michael J. Mahon) wrote:
> SlickRCBD asked:
>
> >I remember seeing an AppleSoft program that would accept a decimal input
> >and convert the number to hex and binary.
> >
> >While writing it wouldn't be all that difficult, and probably only take me
> >an hour or two, I'm wondering if there is a nicer program written in
> >AppleSoft already on the web. That is, nicer than what I would make for my
> >own usage. I think the program I remember might have been in a Nibble
> >disk, but I have no idea what volume, and I don't rememebr which archive
> >has it.
> >
> >I mostly want an AppleSoft implimentation so I can both use the program,
> >and rip the code for my own usage in making a little assistant while I
> >program on my Mac, which is located about 3 feet away from the IIGS with
> >my ImageWrite II in between.
>
> The basic (both senses) routine is:
>
> 100 REM N = positive integer to be converted to hex
> 110 hx$ = ""
> 120 nn = int(n/16)
> 130 h = n - nn*16
> 140 n = nn
> 150 hx$ = mid("0123456789ABCDEF",h,1) + hx$
> 160 if n>0 goto 120
> 170 print hx$
>
> This can be easily adapted for any other radix, including binary, by
> changing "16" to the desired radix and shortening or lenghtening the
> digit translation string in line 150.
>
> -michael
>
> Check out 8-bit Apple sound that will amaze you on my
> Home page: http://members.aol.com/MJMahon/
I already wrote something different by the time you posted this yesteday.
As for your routine, I believe you have a couple of bugs.
First of all, it's MID$, not MID. Second of all, you switched some
variable placement around. H does not show the proper digit for 16, NN
does. You also don't assign n to the 10s column. You assign it to H.
The debugged routine is as follows:
100 REM N = Positive integer to be converted to hex
110 hx$ =""
120 nn=int(n/16)
130 h=n-nn*16
140 n=h
150 hx$ = mid$("0123456789ABCDEF",nn,1) + hx$
160 if n > 0 goto 120
170 print hx$
Not that different from what I did, except I combined an additional
routine to make binary numbers. Too bad I couldn't finish testing my code
before the monitor went out.
--
I do NOT consent to recieve advertisements, special offers, promotions,
OR any other form of unsolicited e-mail, especially commercial or bulk
e-mail. This overides all other forms of consent. My real email is
SLICK underscore(_) RCBD at HOTMAIL, a dot(.) COM
SlickRCBD replied:
>In article <20020816170101.25039.00001067@mb-md.aol.com>, mjmahon@aol.com
>(Michael J. Mahon) wrote:
>
>> SlickRCBD asked:
>>
>> >I remember seeing an AppleSoft program that would accept a decimal input
>> >and convert the number to hex and binary.
>> >
>> >While writing it wouldn't be all that difficult, and probably only take me
>> >an hour or two, I'm wondering if there is a nicer program written in
>> >AppleSoft already on the web. That is, nicer than what I would make for my
>> >own usage. I think the program I remember might have been in a Nibble
>> >disk, but I have no idea what volume, and I don't rememebr which archive
>> >has it.
>> >
>> >I mostly want an AppleSoft implimentation so I can both use the program,
>> >and rip the code for my own usage in making a little assistant while I
>> >program on my Mac, which is located about 3 feet away from the IIGS with
>> >my ImageWrite II in between.
>>
>> The basic (both senses) routine is:
>>
>> 100 REM N = positive integer to be converted to hex
>> 110 hx$ = ""
>> 120 nn = int(n/16)
>> 130 h = n - nn*16
>> 140 n = nn
>> 150 hx$ = mid("0123456789ABCDEF",h,1) + hx$
>> 160 if n>0 goto 120
>> 170 print hx$
>>
>> This can be easily adapted for any other radix, including binary, by
>> changing "16" to the desired radix and shortening or lenghtening the
>> digit translation string in line 150.
>>
>> -michael
>>
>> Check out 8-bit Apple sound that will amaze you on my
>> Home page: http://members.aol.com/MJMahon/
>
>I already wrote something different by the time you posted this yesteday.
>As for your routine, I believe you have a couple of bugs.
Yes, I figured you would have it written!
>First of all, it's MID$, not MID.
Of course! ;-)
> Second of all, you switched some
>variable placement around. H does not show the proper digit for 16, NN
>does. You also don't assign n to the 10s column. You assign it to H.
No, it looks correct as written. The low hex digit of 16 is "0", and
n will be 1 on the next iteration to produce the "1" for $10.
The variable h is the "shifted out" low hex digit, from 0..15.
The variable n must be replaced by int(n/16) since it is the
"right shifted" value of n.
This routine will work on any representable integer, not just
0..255.
The following routine does not work.
>The debugged routine is as follows:
>100 REM N = Positive integer to be converted to hex
>110 hx$ =""
>120 nn=int(n/16)
>130 h=n-nn*16
>140 n=h
>150 hx$ = mid$("0123456789ABCDEF",nn,1) + hx$
>160 if n > 0 goto 120
>170 print hx$
The change to line 140 will exit after one digit with any
multiple of 16. My routine produced the hex digits from
the lowest to the highest--that's why line 150 concatenates
the new digit to the left of the previous digits. This routine
will print out the two hex digits of a single byte in reverse
order, and only if the value is not a multiple of 16.
>Not that different from what I did, except I combined an additional
>routine to make binary numbers. Too bad I couldn't finish testing my code
>before the monitor went out.
-michael
Check out 8-bit Apple sound that will amaze you on my
Home page: http://members.aol.com/MJMahon/