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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [newlib-1.18.0/] [newlib/] [libc/] [stdlib/] [l64a.c] - Blame information for rev 862

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

Line No. Rev Author Line
1 207 jeremybenn
/* l64a - convert long to radix-64 ascii string
2
 *
3
 * Conversion is performed on at most 32-bits of input value starting
4
 * from least significant bits to the most significant bits.
5
 *
6
 * The routine splits the input value into groups of 6 bits for up to
7
 * 32 bits of input.  This means that the last group may be 2 bits
8
 * (bits 30 and 31).
9
 *
10
 * Each group of 6 bits forms a value from 0-63 which is converted into
11
 * a character as follows:
12
 *         0 = '.'
13
 *         1 = '/'
14
 *         2-11 = '0' to '9'
15
 *        12-37 = 'A' to 'Z'
16
 *        38-63 = 'a' to 'z'
17
 *
18
 * When the remaining bits are zero or all 32 bits have been translated,
19
 * a nul terminator is appended to the resulting string.  An input value of
20
 * 0 results in an empty string.
21
 */
22
 
23
#include <_ansi.h>
24
#include <stdlib.h>
25
#include <reent.h>
26
 
27
static const char R64_ARRAY[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
28
 
29
char *
30
_DEFUN (l64a, (value),
31
     long value)
32
{
33
  return _l64a_r (_REENT, value);
34
}
35
 
36
char *
37
_DEFUN (_l64a_r, (rptr, value),
38
     struct _reent *rptr _AND
39
     long value)
40
{
41
  char *ptr;
42
  char *result;
43
  int i, index;
44
  unsigned long tmp = (unsigned long)value & 0xffffffff;
45
 
46
  _REENT_CHECK_MISC(rptr);
47
  result = _REENT_L64A_BUF(rptr);
48
  ptr = result;
49
 
50
  for (i = 0; i < 6; ++i)
51
    {
52
      if (tmp == 0)
53
        {
54
          *ptr = '\0';
55
          break;
56
        }
57
 
58
      index = tmp & (64 - 1);
59
      *ptr++ = R64_ARRAY[index];
60
      tmp >>= 6;
61
    }
62
 
63
  return result;
64
}

powered by: WebSVN 2.1.0

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