Hov to convert pseudo hex to Int ? e.g. 'F' = 16

Hov to conver pseudo hex to Int ?
I need convert
‘1’ >1
‘2’ >2

‘F’ >16
‘G’ >17

julia> typeof(woj16)
Array{Any,1}

julia> typeof(woj16[1])
Char

julia> sort(unique(woj16))
16-element Array{Any,1}:
‘1’
‘2’
‘3’
‘4’
‘5’
‘6’
‘7’
‘8’
‘9’
‘A’
‘B’
‘C’
‘D’
‘E’
‘F’
‘G’

If you do not need range checking you could write:

function c2i(c::Char)
    c <= '9' && return c - '0'
    c - '7'
end

and now you can use it like:

x = ['1':'9'; 'A':'G']
c2i.(x)

this is assuming that you want 'A' to be converted to 10, but then 'F' is 15 not 16 as in your question.

julia> x = ['1':'9'; 'A':'F']
15-element Array{Char,1}:
 '1'
 '2'
 '3'
 '4'
 '5'
 '6'
 '7'
 '8'
 '9'
 'A'
 'B'
 'C'
 'D'
 'E'
 'F'

julia> parse.([Int], x, [16])
15-element Array{Int64,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
2 Likes
function wev(c::Char)
    '1' <= c <= '9' && return c - '0'
    'A' <= c <= 'G' && return c - 'A' + 11
    throw(DomainError())
end
1 Like