Is there a function in C++ like VB's Hex function? ... I dont feel like writing my own :(
Printable View
Is there a function in C++ like VB's Hex function? ... I dont feel like writing my own :(
how about sprintf with "%X"
Code:#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
using namespace std;
string Hex(unsigned long num) {
ostringstream oss;
oss << hex << num;
return oss.str();
}
int main() {
unsigned long number = 0xDEADBEEF;
unsigned long another = 0x1COFFEE1;
cout << "0x" << hex << number << endl;
cout << "0x" << Hex(another) << endl;
}
only problem is.... i want to put the hexed result into a char array.
I need something like...
Hex(int number, char* result);
Ah, just noticed the sprintf post..... I forgot all about sprintf :D
You asked for C++, so that's what I gave you. Why a char array? What's wrong with a string?
I looked at your code to fast.... thought it did something i didnt want ;)
parksie, you forgot
0x1BADF00D