ucspi-ssl  0.99e
TLS encryption for IPv6 communication
hexconversion.c
Go to the documentation of this file.
1 #include "hexconversion.h"
8 void bytetohex(unsigned char decimal, char hex[3]) {
9 
10  const char *hexdigits = "0123456789ABCDEF";
11  int rest, number;
12  hex[0] = '0';
13  hex[1] = '0';
14  hex[2] = '\0';
15 
16  number = decimal / 16;
17  rest = decimal % 16;
18 
19  hex[0] = hexdigits[number];
20  hex[1] = hexdigits[rest];
21 }
22 
23 char tohex(char num) {
24  if (num<10)
25  return num+'0';
26  else if (num<16)
27  return num-10+'a';
28  else
29  return -1;
30 }
31 
32 int fromhex(unsigned char c) {
33  if (c>='0' && c<='9')
34  return c-'0';
35  else if (c>='A' && c<='F')
36  return c-'A'+10;
37  else if (c>='a' && c<='f')
38  return c-'a'+10;
39  return -1;
40 }
char tohex(char num)
Definition: hexconversion.c:23
void bytetohex(unsigned char decimal, char hex[3])
Definition: hexconversion.c:8
int fromhex(unsigned char c)
Definition: hexconversion.c:32