avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] Printf with leading zeros?


From: Michael N. Moran
Subject: Re: [avr-chat] Printf with leading zeros?
Date: Tue, 01 Feb 2011 08:49:10 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Thunderbird/3.1.7

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.



--
Michael N. Moran           (h) 770 516 7918
5009 Old Field Ct.         (c) 678 521 5460
Kennesaw, GA, USA 30144    http://mnmoran.org

"So often times it happens, that we live our lives in chains
 and we never even know we have the key."
"Already Gone" by Jack Tempchin (recorded by The Eagles)

The Beatles were wrong: 1 & 1 & 1 is 1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]