mirror of
https://github.com/apache/nuttx.git
synced 2026-08-03 21:29:02 +00:00
Botched the case for n=0
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@40 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
4c61b4d89c
commit
282b5da0c3
1 changed files with 24 additions and 9 deletions
|
|
@ -270,15 +270,15 @@ static void utodec(struct lib_stream_s *obj, unsigned int n)
|
|||
|
||||
static void utohex(struct lib_stream_s *obj, unsigned int n, ubyte a)
|
||||
{
|
||||
boolean nonleading = FALSE;
|
||||
boolean nonzero = FALSE;
|
||||
ubyte bits;
|
||||
|
||||
for (bits = 8*sizeof(unsigned int); bits > 0; bits -= 4)
|
||||
{
|
||||
ubyte nibble = (ubyte)((n >> (bits - 4)) & 0xf);
|
||||
if (nibble || nonleading)
|
||||
if (nibble || nonzero)
|
||||
{
|
||||
nonleading = TRUE;
|
||||
nonzero = TRUE;
|
||||
|
||||
if (nibble < 10)
|
||||
{
|
||||
|
|
@ -290,6 +290,11 @@ static void utohex(struct lib_stream_s *obj, unsigned int n, ubyte a)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!nonzero)
|
||||
{
|
||||
obj->put(obj, '0');
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
|
|
@ -518,15 +523,15 @@ static void lutodec(struct lib_stream_s *obj, unsigned long n)
|
|||
|
||||
static void lutohex(struct lib_stream_s *obj, unsigned long n, ubyte a)
|
||||
{
|
||||
boolean nonleading = FALSE;
|
||||
boolean nonzero = FALSE;
|
||||
ubyte bits;
|
||||
|
||||
for (bits = 8*sizeof(unsigned long); bits > 0; bits -= 4)
|
||||
{
|
||||
ubyte nibble = (ubyte)((n >> (bits - 4)) & 0xf);
|
||||
if (nibble || nonleading)
|
||||
if (nibble || nonzero)
|
||||
{
|
||||
nonleading = TRUE;
|
||||
nonzero = TRUE;
|
||||
|
||||
if (nibble < 10)
|
||||
{
|
||||
|
|
@ -538,6 +543,11 @@ static void lutohex(struct lib_stream_s *obj, unsigned long n, ubyte a)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!nonzero)
|
||||
{
|
||||
obj->put(obj, '0');
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
|
|
@ -763,15 +773,15 @@ static void llutodec(struct lib_stream_s *obj, unsigned long long n)
|
|||
|
||||
static void llutohex(struct lib_stream_s *obj, unsigned long long n, ubyte a)
|
||||
{
|
||||
boolean nonleading = FALSE;
|
||||
boolean nonzero = FALSE;
|
||||
ubyte bits;
|
||||
|
||||
for (bits = 8*sizeof(unsigned long long); bits > 0; bits -= 4)
|
||||
{
|
||||
ubyte nibble = (ubyte)((n >> (bits - 4)) & 0xf);
|
||||
if (nibble || nonleading)
|
||||
if (nibble || nonzero)
|
||||
{
|
||||
nonleading = TRUE;
|
||||
nonzero = TRUE;
|
||||
|
||||
if (nibble < 10)
|
||||
{
|
||||
|
|
@ -783,6 +793,11 @@ static void llutohex(struct lib_stream_s *obj, unsigned long long n, ubyte a)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!nonzero)
|
||||
{
|
||||
obj->put(obj, '0');
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue