is there is any fun in the c++ library that takes a dec and return hex

Recommended Answers

sprintf() will do it -- the format string is "%x" or "%X"

Jump to Post

I would think sprintf() is as much C++ as null terminated char arrays are. However, if you don't like using C style I/O and all you want to do is to see the hex equivalent of a value, not manipulate the hex equivalent of a value, then there is a …

Jump to Post

All 6 Replies

sprintf() will do it -- the format string is "%x" or "%X"

that's c not c++
do u know anyother sol. in c++

I would think sprintf() is as much C++ as null terminated char arrays are. However, if you don't like using C style I/O and all you want to do is to see the hex equivalent of a value, not manipulate the hex equivalent of a value, then there is a stream flag/modifier by the name of hex that can be used to view the value of a numeric variable as hex as opposed to dec.

>that's c not c++
sprintf is C++ too.

>do u know anyother sol. in c++
Yes, use the hex manipulator with either cout or a string stream. Alternatively, you can do the conversion manually, but since that's available in C as well, I guess it doesn't count as C++. :icon_rolleyes:

if you can send an example please, how can i write it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.