FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
str_hex_lng.c
Go to the documentation of this file.
1
/* hex$ routine for long long's */
2
3
#include "
fb.h
"
4
5
static
char
hex_table
[16] = {
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
};
6
7
FBCALL
FBSTRING
*
fb_HEXEx_l
(
unsigned
long
long
num,
int
digits )
8
{
9
FBSTRING
*s;
10
int
i;
11
unsigned
long
long
num2;
12
13
if
( digits <= 0 ) {
14
/* Only use the minimum amount of digits needed; need to count
15
the important 4-bit (base 16) chunks in the number.
16
And if it's zero, use 1 digit for 1 zero. */
17
digits = 0;
18
num2 = num;
19
while
( num2 ) {
20
digits += 1;
21
num2 >>= 4;
22
}
23
if
( digits == 0 )
24
digits = 1;
25
}
26
27
s =
fb_hStrAllocTemp
(
NULL
, digits );
28
if
( s ==
NULL
)
29
return
&
__fb_ctx
.
null_desc
;
30
31
i = digits - 1;
32
while
( i >= 0 ) {
33
s->
data
[i] =
hex_table
[num & 0xF];
34
num >>= 4;
35
i -= 1;
36
}
37
38
s->
data
[digits] =
'\0'
;
39
return
s;
40
}
41
42
FBCALL
FBSTRING
*
fb_HEX_l
(
unsigned
long
long
num )
43
{
44
return
fb_HEXEx_l
( num, 0 );
45
}
rtlib
str_hex_lng.c
Generated on Thu Jan 23 2014 19:40:13 for FreeBASIC by
1.8.4