void IntToHex( int input, char * output )
{
sprint( output, "%X", input );
}
Then, declare a local external function in PB as follows:
SUBROUTINE IntToHex( long input, REF string output ) LIBRARY
"mysimpledll.dll"
Sample PowerScript:
String ls_hex
ls_hex = Space( 10 )
IntToHex( 1487, ls_hex )
MessageBox( "Hex Conversion", String( 1847 ) + " = " + ls_hex )
--
<hopethishelps/>
Roy Kiesler [TeamSybase]
SDN CodeXchange -- http://codexchange.sybase.com
"Open Support" <sup...@open-solutions.gr> wrote in message
news:eIZMy1dSDHA.344@forums-2-dub...
> Hi all,
>
> I want to convert with PB7 a decimal value (ie 1487) to a hex 2-bytes
> number.
> Simple question, but does anyone knows how to make it work
>
> Thank you in advance
>
> Alex /Open Support
>
>
If you simply want to know that 1487 is equal to 5CF and want the result in
a string you can use this recursive function:
Just give as parameters:
input = 1487
exponent = 0 (startingpoint)
groundnumber = 16 (hex) (also: 8 for oct, 2 for binary, etc.)
$PBExportHeader$r_convert_from_dec.srf
global type r_convert_from_dec from function_object
end type
forward prototypes
global function string r_convert_from_dec (ref decimal input, decimal
exponent, decimal groundnumber)
end prototypes
global function string r_convert_from_dec (ref decimal input, decimal
exponent, decimal groundnumber);
string returnvalue
decimal{0} factor
if groundnumber ^ exponent > input then
return( '' )
else
returnvalue = r_convert_from_dec( input, exponent + 1, groundnumber )
end if
factor = truncate( ( input / ( groundnumber ^ exponent ) ), 0 )
input = input - ( ( groundnumber ^ exponent ) * factor )
if factor < 10 then
return( returnvalue + string( factor ) )
else
return( returnvalue + char( asc( 'A' ) + factor - 10 ) )
end if
end function
Greetings
Eric Rutgers
"Open Support" <sup...@open-solutions.gr> wrote in message
news:eIZMy1dSDHA.344@forums-2-dub...