Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert Decimal To 2-Bytes Hex Value

520 views
Skip to first unread message

Roy Kiesler [TeamSybase]

unread,
Jul 14, 2003, 2:29:24 PM7/14/03
to
The easiest way I can think of is to write a small DLL that exports a
function like the following:

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
>
>


Open Support

unread,
Jul 14, 2003, 3:48:34 AM7/14/03
to

Eric Rutgers

unread,
Jul 18, 2003, 5:36:44 AM7/18/03
to
Hello Alex,

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...

0 new messages