FreeBASIC  0.91.0
str_oct_lng.c
Go to the documentation of this file.
1 /* oct$ routine for long long's */
2 
3 #include "fb.h"
4 
5 FBCALL FBSTRING *fb_OCTEx_l ( unsigned long long num, int digits )
6 {
7  FBSTRING *s;
8  int i;
9  unsigned long long num2;
10 
11  if( digits <= 0 ) {
12  /* Only use the minimum amount of digits needed; need to count
13  the important 3-bit (base 8) chunks in the number.
14  And if it's zero, use 1 digit for 1 zero. */
15  digits = 0;
16  num2 = num;
17  while( num2 ) {
18  digits += 1;
19  num2 >>= 3;
20  }
21  if( digits == 0 )
22  digits = 1;
23  }
24 
25  s = fb_hStrAllocTemp( NULL, digits );
26  if( s == NULL )
27  return &__fb_ctx.null_desc;
28 
29  i = digits - 1;
30  while( i >= 0 ) {
31  s->data[i] = '0' + (num & 7); /* '0'..'7' */
32  num >>= 3;
33  i -= 1;
34  }
35 
36  s->data[digits] = '\0';
37  return s;
38 }
39 
40 FBCALL FBSTRING *fb_OCT_l ( unsigned long long num )
41 {
42  return fb_OCTEx_l( num, 0 );
43 }