1830407 Members
3891 Online
110002 Solutions
New Discussion

Re: Hex to Decimal

 
SOLVED
Go to solution
Aaron Lewis_1
Frequent Advisor

Hex to Decimal

Is there a quick way to convert a HEX value to decimal in a script?
5 REPLIES 5
Uwe Zessin
Honored Contributor
Solution

Re: Hex to Decimal

Yes, pretty easy:

$ v = %xfe
$ show symbol v
V = 254 Hex = 000000FE Octal = 00000000376
$

$ h = "A7"
$ v = %x'h'
$ show symbol v
V = 167 Hex = 000000A7 Octal = 00000000247
$

$ write sys$output %xc9
201
$

.
Aaron Lewis_1
Frequent Advisor

Re: Hex to Decimal

Thanx!!!
Jan van den Ende
Honored Contributor

Re: Hex to Decimal

Aaron,

You asked: "in a script"

Probably then, the best thing is F$FAO.

-- use an integer value as Oct, Dec, Hex string:

$ write sys$output "Hex value of ''int' :", f$fao("!XL", int )

$ write sys$output "Oct value of ''int' :", f$fao("!OL", int )

For decimal, 7 positions WITH leading zeroes:

$ write sys$output "7digit value of ''int' :", f$fao("!7ZL", int )


For decimal, 7 positions SUPPRESSING leading zeroes:

$ write sys$output "7 pos right adjust value of ''int' :", f$fao("!7SL", int )

- the S every time stands for Longword, X for Hex, O for Oct, Z for (leading) Zeroes, S for (leading) Spaces.
A number between the "!" and the format specifier is the number of positions.


It DOES take some getting used to, but its uses are simply phantastic.

HELP LEXICAL F$FAO ARG for MUCH more!

Proost.

Have one on me.

jpe

Don't rust yours pelled jacker to fine doll missed aches.
Robert_Boyd
Respected Contributor

Re: Hex to Decimal

Jan,

It's the L that stands for Longword

The S stands for Signed, not spaces. It does have the additional effect of filling with blanks if the width of the field is specified.
The Z format causes the sign of the value to be ignored.

!SL produces no blanks
!nSL will produce leading blanks if the number is smaller than the field.

Robert
Master you were right about 1 thing -- the negotiations were SHORT!
Jan van den Ende
Honored Contributor

Re: Hex to Decimal

Robert,

the "L" was a typo.
I did not know about "S" for Signed, I always use it for what you call the additional effect.
Does "Z" really IGNORE the sign, or does it treat the Longword as UNsigned?
I will have to test it sometime.

Proost.

Have one on me.

jpe

Don't rust yours pelled jacker to fine doll missed aches.