[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-chat] Printf with leading zeros?
From: |
Rick Mann |
Subject: |
Re: [avr-chat] Printf with leading zeros? |
Date: |
Tue, 1 Feb 2011 10:32:33 -0800 |
On Feb 1, 2011, at 05:49:10, Michael N. Moran wrote:
> On 02/01/2011 04:19 AM, Rick Mann wrote:
>> I'm trying to output a byte as a hex value with zero padding. I do something
>> like this:
>>
>> uint8_t val = 4;
>> int len = snprintf((char*) sBuf, 64, "%02x\r\n", val);
>
> I use this format "%2.2x" to get the behaviour you desire.
I tried that, and it had no effect. Moreover, it shouldn't be necessary.
I noticed that switching to the floating point version of the library improved
things, but didn't fix them altogether. For example, I added some logging to my
code that uses "%#02x". This is supposed to produce strings that look like:
0x00
0x01
0xff
etc
But the actual output depends on the value. If
Hex value Output
--------- ------
0x00 00
0x01 0x1
0x06 0x6
0xb0 0xb0
0x69 0x69
There is clearly something broken in the library.
--
Rick
- [avr-chat] Printf with leading zeros?, Rick Mann, 2011/02/01
- Re: [avr-chat] Printf with leading zeros?, Michael N. Moran, 2011/02/01
- Re: [avr-chat] Printf with leading zeros?,
Rick Mann <=
- Re: [avr-chat] Printf with leading zeros?, Andy Warner, 2011/02/01
- Re: [avr-chat] Printf with leading zeros?, Rick Mann, 2011/02/01
- RE: [avr-chat] Printf with leading zeros?, Weddington, Eric, 2011/02/01
- Re: [avr-chat] Printf with leading zeros?, Rick Mann, 2011/02/01
- Re: [avr-chat] Printf with leading zeros?, Rick Mann, 2011/02/01
- Re: [avr-chat] Printf with leading zeros?, Joerg Wunsch, 2011/02/04