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

Subversion Repositories openfire2

[/] [openfire2/] [trunk/] [sw/] [lib/] [gethexstring.c] - Diff between revs 4 and 6

Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 6
#include "openfire.h"
#include "openfire.h"
 
 
static unsigned gethexchar(char c)
static unsigned gethexchar(char c)
{
{
  if(c >= 'a') c = c - 'a' + '0' + 10;
  if(c >= 'a') c = c - 'a' + '0' + 10;
  else if(c >= 'A') c = c - 'A' + '0' + 10;
  else if(c >= 'A') c = c - 'A' + '0' + 10;
  return c - '0';
  return c - '0';
}
}
 
 
static unsigned ishexdigit(char c)
static unsigned ishexdigit(char c)
{
{
  return (c >= '0' && c <= '9') ||
  return (c >= '0' && c <= '9') ||
         (c >= 'a' && c <= 'f') ||
         (c >= 'a' && c <= 'f') ||
         (c >= 'A' && c <= 'F');
         (c >= 'A' && c <= 'F');
}
}
 
 
char *gethexstring(char *string, unsigned *value, unsigned maxdigits)
char *gethexstring(char *string, unsigned *value, unsigned maxdigits)
{
{
  unsigned number = 0;
  unsigned number = 0;
 
 
  while( ishexdigit( string[0] ) && maxdigits > 0)
  while( ishexdigit( string[0] ) && maxdigits > 0)
  {
  {
    number <<= 4;
    number <<= 4;
    number |= gethexchar(string[0]);
    number |= gethexchar(string[0]);
    string++;
    string++;
    maxdigits--;
    maxdigits--;
  }
  }
 
 
  *value = number;
  *value = number;
  return string;
  return string;
}
}
 
 

powered by: WebSVN 2.1.0

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