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

**URL:** <https://discourse.julialang.org/t/hov-to-convert-pseudo-hex-to-int-e-g-f-16/2314>\
**Category:** General Usage\
**Created:** [February 26, 2017, 7:27am UTC](https://discourse.julialang.org/t/hov-to-convert-pseudo-hex-to-int-e-g-f-16/2314 "2017-02-26T07:27:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [February 26, 2017, 7:27am UTC](https://discourse.julialang.org/t/hov-to-convert-pseudo-hex-to-int-e-g-f-16/2314/1 "2017-02-26T07:27:53Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [February 26, 2017, 7:53am UTC](https://discourse.julialang.org/t/hov-to-convert-pseudo-hex-to-int-e-g-f-16/2314/2 "2017-02-26T07:53:19Z")

</div>

If you do not need range checking you could write:

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

```

and now you can use it like:

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

---

<div class="post-metadata">

**Author:** ![innerlee](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@innerlee](https://discourse.julialang.org/u/innerlee)\
**Post date:** [February 26, 2017, 8:36am UTC](https://discourse.julialang.org/t/hov-to-convert-pseudo-hex-to-int-e-g-f-16/2314/3 "2017-02-26T08:36:12Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![jpiitula](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpiitula/32/471_2.png) [@jpiitula](https://discourse.julialang.org/u/jpiitula)\
**Post date:** [February 26, 2017, 9:37am UTC](https://discourse.julialang.org/t/hov-to-convert-pseudo-hex-to-int-e-g-f-16/2314/4 "2017-02-26T09:37:04Z")

</div>

```julia
function wev(c::Char)
    '1' <= c <= '9' && return c - '0'
    'A' <= c <= 'G' && return c - 'A' + 11
    throw(DomainError())
end

```
