Convert String value to HEX

I need to know how to convert char to its decimal equivalent for example I have J in a char array I need to convert it to 74 which is the decimal equalant for J in ASCII.
Tried atoi,atol didn't help
also tried creating an array from 0- 100 like this char ascii={'','','','','',''} but It doesn't work after ♪ character
Any help is appreciated
Thanks

Serial.print ('J', HEX);

You will need to apply appropriate indices.

1 Like

Thank you for the reply but how can I put char array element into something like this and get the output to an integer?

You could cast the char element to a byte or unsigned integer.

1 Like

all data is binary. you can represent data it in many different ways that are all equivalent

the code below produces

 val is 74
 val is 'J'
 val is 0x4A
    0 0x00  
    1 0x01  
    2 0x02  
    3 0x03  
    4 0x04  
    5 0x05  
    6 0x06  
    7 0x07  a
    8 0x08  
    9 0x09  	
   10 0x0a  

   11 0x0b  
   12 0x0c  
   13 0x0d  

   14 0x0e  
   15 0x0f  
   16 0x10  
   17 0x11  
   18 0x12  
   19 0x13  
   20 0x14  
   21 0x15  
   22 0x16  
   23 0x17  
   24 0x18  
   25 0x19  
   26 0x1a  
   27 0x1b  e
   28 0x1c  
   29 0x1d  
   30 0x1e  
   31 0x1f  
   32 0x20   
   33 0x21  !
   34 0x22  "
   35 0x23  #
   36 0x24  $
   37 0x25  %
   38 0x26  &
   39 0x27  '
   40 0x28  (
   41 0x29  )
   42 0x2a  *
   43 0x2b  +
   44 0x2c  ,
   45 0x2d  -
   46 0x2e  .
   47 0x2f  /
   48 0x30  0
   49 0x31  1
   50 0x32  2
   51 0x33  3
   52 0x34  4
   53 0x35  5
   54 0x36  6
   55 0x37  7
   56 0x38  8
   57 0x39  9
   58 0x3a  :
   59 0x3b  ;
   60 0x3c  <
   61 0x3d  =
   62 0x3e  >
   63 0x3f  ?
   64 0x40  @
   65 0x41  A
   66 0x42  B
   67 0x43  C
   68 0x44  D
   69 0x45  E
   70 0x46  F
   71 0x47  G
   72 0x48  H
   73 0x49  I
   74 0x4a  J
   75 0x4b  K
   76 0x4c  L
   77 0x4d  M
   78 0x4e  N
   79 0x4f  O
   80 0x50  P
   81 0x51  Q
   82 0x52  R
   83 0x53  S
   84 0x54  T
   85 0x55  U
   86 0x56  V
   87 0x57  W
   88 0x58  X
   89 0x59  Y
   90 0x5a  Z
   91 0x5b  [
   92 0x5c  \
   93 0x5d  ]
   94 0x5e  ^
   95 0x5f  _
   96 0x60  `
   97 0x61  a
   98 0x62  b
   99 0x63  c
  100 0x64  d
  101 0x65  e
  102 0x66  f
  103 0x67  g
  104 0x68  h
  105 0x69  i
  106 0x6a  j
  107 0x6b  k
  108 0x6c  l
  109 0x6d  m
  110 0x6e  n
  111 0x6f  o
  112 0x70  p
  113 0x71  q
  114 0x72  r
  115 0x73  s
  116 0x74  t
  117 0x75  u
  118 0x76  v
  119 0x77  w
  120 0x78  x
  121 0x79  y
  122 0x7a  z
  123 0x7b  {
  124 0x7c  |
  125 0x7d  }
  126 0x7e  ~
  127 0x7f  

byte val = 74;
char s [80];

void
scan ()
{
    for (int n = 0; n < 128; n++)  {
        sprintf (s, " %4d 0x%02x  %c", n, n, n);
        Serial.println (s);
    }
}

void setup ()
{
    Serial.begin (9600);

    if (74 == val)
        Serial.println (" val is 74");

    if ('J' == val)
        Serial.println (" val is 'J'");

    if (0x4A == val)
        Serial.println (" val is 0x4A");

    scan ();
}

void loop () {
}
1 Like

Some notes:

    7 0x07  'a'  ASCII BEL (Bell), a.k.a 'alert'
    9 0x09  '	'  ASCII TAB ('\t')
   10 0x0a  '
'  ASCII LF (Linefeed/Newline, '\n')
   13 0x0d  '
'  ASCII CR (Return/Enter, '\r')
   27 0x1b  'e'  ASCII ESC (Escape)
   32 0x20  ' '  (Space)
1 Like

Thank you very much it helped a lot

Thank you for the reply

Thank you for your help