hex to decimal

Prev Next

Function Names

hex to decimal

Description

This function converts a hexadecimal sequence to a number. Range: : 64-bit integer boundary, i.e. max 16 hexadecimal symbols. Negative hexadecimal values, e.g. -0A1, are not allowed. In fact, all non-hexadecimal characters including the minus sign will be ignored, allowing to convert values conveniently such as 0x10ac, #10ac, b>10 ac, etc.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

1-3

Parameters

No.TypeDescription
1.
input
string Hexadecimal value

Hexadecmial digits are 0..9 and A..F or a..f or a combination of them. Other characters and spaces will be ignored.

Opt. 2.
input
numeral Starting character position

Optionaly specify the 1st character position to start decoding, i.e. skip string contents before that position

Default value: 0
Opt. 3.
input
numeral Character count

You can limit the number of character to decode. This is useful for working with long strings containing more than just a hexadecimal value.

Default value: (not limited)

Return value

TypeDescription
numeral Decoded value

Converted from the hexadecimal number. 0 is returned if contents are blank or contain no hexadecimal digits.

Exceptions

Values provided is not a numerals

Examples

  examples[] = { 20AC, 0x20AC, 20ACH, "#20AC", "", "-" };

  for all parameters( examples[], h[] )
  {
      print( hex to decimal( h[] ), "  " );
      echo( "2nd char pos, len = 1: ", hex to decimal( h[], 2, 1 ) );
  }

Output

8364  2nd char pos, len = 1: 10
8364  2nd char pos, len = 1: 2
8364  2nd char pos, len = 1: 10
8364  2nd char pos, len = 1: 0
0  2nd char pos, len = 1: 0
0  2nd char pos, len = 1: 0
Try it yourself: Open LIB_Function_hex_to_decimal.b4p in B4P_Examples.zip. Decompress before use.