|
-
Jul 2nd, 2002, 11:38 PM
#1
Thread Starter
Lively Member
Hex function in C++ ?
Is there a function in C++ like VB's Hex function? ... I dont feel like writing my own
-
Jul 2nd, 2002, 11:48 PM
#2
PowerPoster
how about sprintf with "%X"
-
Jul 3rd, 2002, 12:22 PM
#3
Monday Morning Lunatic
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;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 3rd, 2002, 01:16 PM
#4
Thread Starter
Lively Member
only problem is.... i want to put the hexed result into a char array.
I need something like...
Hex(int number, char* result);
-
Jul 3rd, 2002, 01:18 PM
#5
Thread Starter
Lively Member
Ah, just noticed the sprintf post..... I forgot all about sprintf
-
Jul 3rd, 2002, 01:19 PM
#6
Monday Morning Lunatic
You asked for C++, so that's what I gave you. Why a char array? What's wrong with a string?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 3rd, 2002, 01:23 PM
#7
Thread Starter
Lively Member
I looked at your code to fast.... thought it did something i didnt want
-
Jul 10th, 2002, 07:21 PM
#8
parksie, you forgot
0x1BADF00D
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|