hex to decimal
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.
Indirect parameter passing is disabled
1-3
No. | Type | Description |
---|---|---|
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) |
Type | Description |
---|---|
numeral | Decoded value Converted from the hexadecimal number. 0 is returned if contents are blank or contain no hexadecimal digits. |
Values provided is not a numerals
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 ) );
}
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