473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

printing uin32_t in hexadecimal

Hi.

I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);

my compiler give me the following warning: unsigned int format, uint32_t
arg (arg 2)

Is there any formtat I can use? %08uX ?

thanks

Maxime
Nov 14 '05 #1
10 32049
Maxime Barbeau wrote:
Hi.

I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);

my compiler give me the following warning: unsigned int format, uint32_t
arg (arg 2)

Is there any formtat I can use? %08uX ?


%lx

Tom
Nov 14 '05 #2
On Fri, 13 Aug 2004 15:11 GMT, Tom St Denis <to********@iahu.ca> wrote:
Maxime Barbeau wrote:
I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);

my compiler give me the following warning: unsigned int format, uint32_t
arg (arg 2)

Is there any formtat I can use? %08uX ?


%lx


No, %lx is not completely correct. %lx expects an unsigned long.
Although unsigned long and uint32_t have the same representation on many
systems, there's absolutely no requirement for them to. We do know that
unsigned long is at least 32 bits, so a more proper method would be to
use %lx and cast the argument to unsigned long. That way, if unsigned
long is, say, 64 bits, printf() won't grab an extra 32 bits of junk off
the stack (or whatever method your implementation happens to use for
argument passing).

Chris
Nov 14 '05 #3
Maxime Barbeau wrote:

I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);

my compiler give me the following warning: unsigned int format,
uint32_t arg (arg 2)

Is there any formtat I can use? %08uX ?


Using uint32_t requires #include <stdint.h> and a C99 compiler
system. You probably don't have either.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #4
"Maxime Barbeau" <ma************@mindready.com> writes:
I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);

my compiler give me the following warning: unsigned int format, uint32_t
arg (arg 2)

Is there any formtat I can use? %08uX ?


Where is uint32_t defined? If you're using C99, uint32_t is a typedef
in <stdint.h>; it's probably equivalent to one of unsigned short,
unsigned int, or unsigned long (most likely the latter in your case).
But you don't know which, so you can't safely use a format for one of
the predefined types.

The C99 header <inttypes.h> provides macros that expand to printf
formats for various types, including uint32_t, but they're ugly.

But you know that uint32_t is exactly 32 bits, and you know that
unsigned long is at least 32 bits, so you can do this:

uint32_t quadlet = 0x12345678;
printf("quadlet = %08lX\n", (unsigned long)quadlet);

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
On Fri, 13 Aug 2004 19:07:34 GMT, CBFalconer <cb********@yahoo.com>
wrote in comp.lang.c:
Maxime Barbeau wrote:

I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);

my compiler give me the following warning: unsigned int format,
uint32_t arg (arg 2)

Is there any formtat I can use? %08uX ?


Using uint32_t requires #include <stdint.h> and a C99 compiler
system. You probably don't have either.


That's just plain bullschildt, Chuck.

Using uint32_t requires a <stdint.h> header, or equivalent. Any
conforming C90 compiler that has the right size integer types with 2's
complement representation, and that is the overwhelming majority of
them, will work just fine with a properly written <stdint.h> file, for
whatever subset of C99 integer types that they support and they are
not hard at all to write. They're just typedefs, after all.

Every conforming C89/C90 implementation can support all of the
''least'' and ''fastest'' up to 32 bits, if not 64 bits.

And what conforming implementation have you ever actually used that
did not provide an exact-width 32-bit integer type with no trap
representations and using 2's complement for the signed version?

I've written several (subset) stdint.h headers for a variety of
embedded 16-bit, 32-bit, and DSPs. Heck, the one that comes with
ARM's ADS 1.1 or 1.2 development tools compiles and works perfectly
with Visual C++ 6.

The corresponding <inttypes.h> header with its macros for printf() and
scanf() is more work, but it is also possible and I've done it.

Many compilers, even though they do not support all of C99, include a
working <stdint.h> and <inttypes.h>, even quite a few available for
free download. All of the 32-bit ones I know of support the 64-bit
types as well. Here's a list of compilers that I know have these
headers:

-- Borland's free C++BuilderX

-- mingw

-- gcc

-- lcc-win32

-- Codewarrior for Windows

-- ARM ADS

-- IAR for ARM

....and I've made subset headers that worked on platforms like TI DSPs
and 16 micros. Heck, I could write subset headers in half an hour or
less for an 8051, if I couldn't get out of never using on again.

So come off your high horse, you do not need C99 for using and
printing uint32_t, all you need is a pair of headers that can be used
quite well in C89/C90, or in some K&R 1 implementations for that
matter. It requires no language features at all, just typedefs and
the automatic string concatenation for the <inttypes.h> macros that
wasn't universal until C89.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #6
Jack Klein wrote:
CBFalconer <cb********@yahoo.com> wrote in comp.lang.c:
Maxime Barbeau wrote:

I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);

my compiler give me the following warning: unsigned int format,
uint32_t arg (arg 2)

Is there any formtat I can use? %08uX ?


Using uint32_t requires #include <stdint.h> and a C99 compiler
system. You probably don't have either.


That's just plain bullschildt, Chuck.

Using uint32_t requires a <stdint.h> header, or equivalent. Any
conforming C90 compiler that has the right size integer types with 2's
complement representation, and that is the overwhelming majority of
them, will work just fine with a properly written <stdint.h> file, for
whatever subset of C99 integer types that they support and they are
not hard at all to write. They're just typedefs, after all.


Am I wrong that stdint.h did not exist in C90? M. Barbeau
certainly did not show any definitions for that term. Isn't
uint_32 implementation optional even in C99?

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #7
CBFalconer <cb********@yahoo.com> writes:
Jack Klein wrote:
CBFalconer <cb********@yahoo.com> wrote in comp.lang.c:
Maxime Barbeau wrote:

I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);

my compiler give me the following warning: unsigned int format,
uint32_t arg (arg 2)

Is there any formtat I can use? %08uX ?

Using uint32_t requires #include <stdint.h> and a C99 compiler
system. You probably don't have either.


That's just plain bullschildt, Chuck.

Using uint32_t requires a <stdint.h> header, or equivalent. Any
conforming C90 compiler that has the right size integer types with 2's
complement representation, and that is the overwhelming majority of
them, will work just fine with a properly written <stdint.h> file, for
whatever subset of C99 integer types that they support and they are
not hard at all to write. They're just typedefs, after all.


Am I wrong that stdint.h did not exist in C90? M. Barbeau
certainly did not show any definitions for that term. Isn't
uint_32 implementation optional even in C99?


uint32_t is mandatory in C99 if (and only if) the implementation
provides a 32-bit two's complement integer type with no padding bits.
(The standard's wording is a trifle ambiguous, but I think there's a
DR clarifying it.) But there are C90-compatible implementations of
<stdint.h>.

Note that the original poster got an error message for the printf
format but not for the declaration of quadlet, so there must have been
a declaration of uint32_t somewhere.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #8
Hello every one.

Thanks for your help

I am writing a program that will go on an embedded system.
I am using VxWorks for x86 and the PPC family.
This code is shared with QNX and will probably go under other OSs and CPUs.

The #include <inttypes.h> or <stdint.h> is certainly included in the header
I use.

After reading the posts, I guess I can use printf("quadlet: %08lX\n",
quadlet);
Maxime

"Maxime Barbeau" <ma************@mindready.com> wrote in message
news:lR*******************@weber.videotron.net...
Hi.

I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);

my compiler give me the following warning: unsigned int format, uint32_t
arg (arg 2)

Is there any formtat I can use? %08uX ?

thanks

Maxime

Nov 14 '05 #9
"Maxime Barbeau" <ma************@mindready.com> writes:
I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);


Actually, you want:
printf("quadlet = %"PRIx32"\n", quadlet);
assuming you have a working <inttypes.h>.
--
"The way I see it, an intelligent person who disagrees with me is
probably the most important person I'll interact with on any given
day."
--Billy Chambless
Nov 14 '05 #10
Thanks

Maxime

"Ben Pfaff" <bl*@cs.stanford.edu> wrote in message
news:87************@benpfaff.org...
"Maxime Barbeau" <ma************@mindready.com> writes:
I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);


Actually, you want:
printf("quadlet = %"PRIx32"\n", quadlet);
assuming you have a working <inttypes.h>.
--
"The way I see it, an intelligent person who disagrees with me is
probably the most important person I'll interact with on any given
day."
--Billy Chambless

Nov 14 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pekka Niiranen | last post by:
Hi there, how can I write out Python Unicode character's hexadecimal value in generic format? I need to loop thru characters in Unicode string and store each character in format \U+hhhh,...
6
by: Enrico `Trippo' Porreca | last post by:
Suppose I wanted to print an unsigned char (in hex). Should I say: unsigned char x = 0x12; printf("%X\n", x); or printf("%X\n", (unsigned) x);
10
by: pavithra.eswaran | last post by:
Hi, I would like to convert a single precision hexadecimal number to floating point. The following program seems to work fine.. But I do not want to use scanf. I already have a 32 bit hexadecimal...
1
by: Fernando Barsoba | last post by:
Hi all, First of all, I'd like to thank you "Skarmander" and "Flash Gordon" for the help they provided me: Skarmander's algorithm and Flash's modifications helped me a lot. Here's the problem...
8
by: Vijay | last post by:
Hi , I am doing a small project in c. I have a Hexadecimal file and want to convert into ascii value. (i.e., Hexadecimal to Ascii conversion from a file). Could anyone help me? Thanks in...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
14
by: abhishekkarnik | last post by:
Hi, I am trying to read an exe file and print it out character by character in hexadecimal format. The file goes something like this in hexadecimal 0x4d 0x5a 0x90 0x00 0x03 .... so on When I...
6
by: Andrea | last post by:
Hi, suppose that I have a string that is an hexadecimal number, in order to print this string I have to do: void print_hex(unsigned char *bs, unsigned int n){ int i; for (i=0;i<n;i++){...
6
by: sweeet_addiction16 | last post by:
hello Im writin a code in c... can sum1 pls help me out in writing a c code to convert decimalnumber to hexadecimal number.The hexadecimal number generated has to be an unsigned long.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.