💾 Archived View for mirrors.apple2.org.za › archive › ground.icaen.uiowa.edu › MiscInfo › Empson › p… captured on 2023-01-29 at 09:42:48.

View Raw

More Information

-=-=-=-=-=-=-


Yves McDonald <""yves.mcdonald\"@NO SPAM sympatico.ca> wrote:

> Is there a way to print integer values in hexadecimal with ORCA/Pascal,
> either with a library procedure or GS Toolbox?

Printing hexadecimal values is not a feature supplied by standard
Pascal, and I can't see any mention of a library function in ORCA/Pascal
to do this.

You could use the Integer Math toolset functions to convert an integer
into a hexadecimal string.  (My Pascal is rusty, so excuse any syntax
errors.)

Procedure PrintHex(intValue, width : integer);
Var s : Str32;
Begin
  If width <= 32 Then
  Begin
    Int2Hex(intValue, @s, width + 1);
    Write(s);
  End;
End;

I expect you will need to USE the appropriate toolset definition file,
and you might need to start up and shut down the IntMath toolset in
order to use it.

There is also a corresponding procedure called Long2Hex, and functions
Hex2Int and Hex2Long (which return an integer and long value
respectively).

> (and suddently, JAVA seems soo convenient :)

ORCA/C would be more convenient, because printf() has always supported
hex data output.

-- 
David Empson
dempson@actrix.gen.nz



Almost there :), the compiler coudn't find Str32 type so I used Orca 
String  type. I got trailing garbage to each hex number I print. I think 
it's because Integer Math tool set conversion routines don't provide 
string termination (C-style) nor lenght info (Pascal-style).  The width 
parameter is actually your string length in bytes so 4+1 is ok for int 
and 8+1 is ok for long integers and pointers.  The '+1' is space for the 
string terminator of course.

Thanks for the tip,

Yves

David Empson wrote:

> Yves McDonald <""yves.mcdonald\"@NO SPAM sympatico.ca> wrote:
> 
> 
>>Is there a way to print integer values in hexadecimal with ORCA/Pascal,
>>either with a library procedure or GS Toolbox?
>>
> 
> Printing hexadecimal values is not a feature supplied by standard
> Pascal, and I can't see any mention of a library function in ORCA/Pascal
> to do this.
> 
> You could use the Integer Math toolset functions to convert an integer
> into a hexadecimal string.  (My Pascal is rusty, so excuse any syntax
> errors.)
> 
> Procedure PrintHex(intValue, width : integer);
> Var s : Str32;
> Begin
>   If width <= 32 Then
>   Begin
>     Int2Hex(intValue, @s, width + 1);
>     Write(s);
>   End;
> End;
> 
> I expect you will need to USE the appropriate toolset definition file,
> and you might need to start up and shut down the IntMath toolset in
> order to use it.
> 
> There is also a corresponding procedure called Long2Hex, and functions
> Hex2Int and Hex2Long (which return an integer and long value
> respectively).
> 
> 
>>(and suddently, JAVA seems soo convenient :)
>>
> 
> ORCA/C would be more convenient, because printf() has always supported
> hex data output.
> 
>