| | |
decimal > binary > Oct > Hex
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I found this link, which you could use to do the decimal to hex number.
But, I'd imagine somewhere there's bound to be some kind of library function that could do this for you... Have you searched Google for it yet?
But, I'd imagine somewhere there's bound to be some kind of library function that could do this for you... Have you searched Google for it yet?
Alex Cavnar, aka alc6379
•
•
•
•
Originally Posted by Transworld
Would I have to go about doing the math manually and make my own function? Is there some built in function I can use to be lazy? Is there some totally easier way that I am oblivious to?
C++ Syntax (Toggle Plain Text)
#include <iostream> template < typename T > inline T highbit(T& t) { return t = (((T)(-1)) >> 1) + 1; } template < typename T > std::ostream& bin(T& value, std::ostream &o) { for ( T bit = highbit(bit); bit; bit >>= 1 ) { o << ( ( value & bit ) ? '1' : '0' ); } return o; } int main() { unsigned long value = 0x12345678; std::cout << "hex: " << std::hex << value << std::endl; std::cout << "dec: " << std::dec << value << std::endl; std::cout << "oct: " << std::oct << value << std::endl; std::cout << "bin: "; bin(value, std::cout); std::cout << std::endl; return 0; } /* my output hex: 12345678 dec: 305419896 oct: 2215053170 bin: 00010010001101000101011001111000 */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Help With Decimal to Binary conversion (IT Professionals' Lounge)
- Converting Decimal Value to Binary (MIPS) (Assembly)
- Convert decimal to binary and with base the 8 (C)
- decimal to binary conversion (C++)
Other Threads in the C++ Forum
- Previous Thread: Can't download page from HTTPS
- Next Thread: A prayer to the C++ God pleaze help!!
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






