ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Sorry to be posting up the forums tonight, or day depending on where you are from.
I have read and experienced that the gnu compiler does not support hexadecimal output? I believe that is right, forgive me if I am wrong. Is there a way around this? Thank you.
What have you been smoking? The GNU compiler is perfectly capable of displaying hexadecimal output. Any compiler that wants to even pretend to be ANSI compliant can display hexadecimal output...
Now, the question is... How do you want to display hexadecimal output exactly, and what language are you using?
If you just want to print a hex value to the screen, you can do something like so with C:
printf("%x", someValue);
Or the following with C++:
cout << hex << someValue; // May want to cast someValue to an int first...
Sorry , thats what I have read twice today. I get the error :segmentation fault when I try.
I am only 3 or 4 months into this so cut me some slack, but thanks. I was reading some of my posts from before and I was chuckling myself, guess I will add a new one to laugh at sometime. I went to the site I got the info from and this is why I was confused.
hex
Print the hexadecimal representation numbers as they are stored in memory. For example, on a workstation which stores 8 byte real values in IEEE format with the least significant byte first, the value of pi when printed in hex format is 400921fb54442d18. This format only works for numeric values.
I am wanting to convert a string of characters in c++ . They are non numeric. For instance a name. Thanks again.
i think you need to be a bit more specific about your problem and which part of your code is causing the seg-fault.
As deiussum said, the GNU Compiler IS capable of displaying hex....
I believe you when you say it will display hex.
I misread that part of the tutorial. However it does state that it only works on numeric values. To error is human.
This code echos the string input. Is there a way for it to display input as a hex value. Again thank you.
{
string input;
cout << Enter your name:
cin >> input;
cout << hex << input;
return 0;
}
For strings, you'll probably need to print each character one at a time. Generally, when I print hex characters, I also like to print a 0 in front of hex values less than 10, so like 0F instead of F... The following code should do that for you
P.S. Sorry if I came across too strong in my previous post. I didn't mean it to come across as insulting in any way.
Also, segmentation faults usually occur when you are touching memory in some way that you have no right to be touching it. (Shame on you! That's a bad touch!) That includes things like dereferencing dangling pointers, going beyond the bounds of an array, trying to change memory that is flagged as "constant," etc.
very cool, no I didn't feel insulted. I am new so I will probably ask questions, or as in my previous post , make statements that others would find entertaiting. Again thank you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.