Menu

[424828]: / src / rtlib / strw_hex_lng.c  Maximize  Restore  History

Download this file

49 lines (40 with data), 993 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* hexw$ routine for long long's */
#include "fb.h"
static FB_WCHAR hex_table[16] = {_LC('0'),_LC('1'),_LC('2'),_LC('3'),
_LC('4'),_LC('5'),_LC('6'),_LC('7'),
_LC('8'),_LC('9'),_LC('A'),_LC('B'),
_LC('C'),_LC('D'),_LC('E'),_LC('F')};
FBCALL FB_WCHAR *fb_WstrHexEx_l ( unsigned long long num, int digits )
{
FB_WCHAR *s;
int i;
unsigned long long num2;
if( digits <= 0 ) {
/* Only use the minimum amount of digits needed; need to count
the important 4-bit (base 16) chunks in the number.
And if it's zero, use 1 digit for 1 zero. */
digits = 0;
num2 = num;
while( num2 ) {
digits += 1;
num2 >>= 4;
}
if( digits == 0 )
digits = 1;
}
s = fb_wstr_AllocTemp( digits );
if( s == NULL )
return NULL;
i = digits - 1;
while( i >= 0 ) {
s[i] = hex_table[num & 0xF];
num >>= 4;
i -= 1;
}
s[digits] = _LC('\0');
return s;
}
FBCALL FB_WCHAR *fb_WstrHex_l ( unsigned long long num )
{
return fb_WstrHexEx_l( num, 0 );
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.