gettign hex code of a byte

Jun 24, 2008 at 9:24pm
earlier, I had posted a problem in which I was advised to look at it in terms of hex values and not binary values, so how do i do this in c++?

As an example lets suppose that int n = 1234, now instead looking at binary I would like to look at it in terms of hex values, so I would like to look at it in by looping through the int and reading 1's hex value, then 2 and so on...

a simple example would be helpful.

thanks
Jun 24, 2008 at 9:39pm
Ok. I am a lil occupied to write you the code.

But, an int is a 4 byte number, this doesn't correlate to 1 being a hex char, 2 being a hex char etc and all added together.

In general hex goes from 0x00 = 0 to 0xFF = 255 for each byte. 0xFFFF (2bytes) maximum value is 65535 (because 0xFFFF = 65535). So the data type 'short' which is 2 bytes can have a maximum value of 65535 (if unsigned).

I'll try and post some more info later for you.
Jun 24, 2008 at 10:06pm
1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main()
{
  int n = 1234;
  cout << "0x" << hex << n << endl;
  return 0;
}


:)
Jun 24, 2008 at 11:53pm
@Zaita,

once again, thanks....!!!!
Topic archived. No new replies allowed.