40 lines
536 B
C
40 lines
536 B
C
|
/*
|
||
|
* num_ops.c
|
||
|
*
|
||
|
* Created on: Aug 27, 2011
|
||
|
* Author: Tiberiu
|
||
|
*/
|
||
|
#include <types.h>
|
||
|
|
||
|
uint32 numlen (int32 number, int32 base)
|
||
|
{
|
||
|
// Sanity check
|
||
|
if (base < 2) return 0;
|
||
|
|
||
|
uint32 len = (number < 0 && base == 10); // add minus sign
|
||
|
if (number == 0) return 1;
|
||
|
|
||
|
while (number) {
|
||
|
number /= base;
|
||
|
++len;
|
||
|
}
|
||
|
|
||
|
return len;
|
||
|
}
|
||
|
|
||
|
uint32 unumlen (uint32 number, int32 base)
|
||
|
{
|
||
|
// Sanity check
|
||
|
if (base < 2) return 0;
|
||
|
|
||
|
uint32 len = 0;
|
||
|
if (number == 0) return 1;
|
||
|
|
||
|
while (number) {
|
||
|
number /= base;
|
||
|
++len;
|
||
|
}
|
||
|
|
||
|
return len;
|
||
|
}
|