OpenCores
URL https://opencores.org/ocsvn/openfire2/openfire2/trunk

Subversion Repositories openfire2

[/] [openfire2/] [trunk/] [sw/] [lib/] [gethexstring.c] - Blame information for rev 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 toni32
#include "openfire.h"
2
 
3
static unsigned gethexchar(char c)
4
{
5
  if(c >= 'a') c = c - 'a' + '0' + 10;
6
  else if(c >= 'A') c = c - 'A' + '0' + 10;
7
  return c - '0';
8
}
9
 
10
static unsigned ishexdigit(char c)
11
{
12
  return (c >= '0' && c <= '9') ||
13
         (c >= 'a' && c <= 'f') ||
14
         (c >= 'A' && c <= 'F');
15
}
16
 
17
char *gethexstring(char *string, unsigned *value, unsigned maxdigits)
18
{
19
  unsigned number = 0;
20
 
21
  while( ishexdigit( string[0] ) && maxdigits > 0)
22
  {
23
    number <<= 4;
24
    number |= gethexchar(string[0]);
25
    string++;
26
    maxdigits--;
27
  }
28
 
29
  *value = number;
30
  return string;
31
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.