messing with hex

I am trying to write a program that will read in four bytes in hex and see if it is <= 07070707(hex)
I am stumped about how to do this
do I have to write it as 0x07 0x07 0x07 0x07?
also would I have to write it back that way if I wrote to a file or could I just write 07070707?
Thanks
Last edited on
Put 0x in front of the number. 0x07070707.
would it still be four bytes with the 0x added on or not?
thanks
closed account (zwA4jE8b)
you could test it with the sizeof() function probably
0x just indicates that the digits following are hexadecimal ones, it has no effect on how the number is stored.
You can write 0x07070707, 117901063 (decimal) or 0701603407 (octal) - all three specify the same number.
Here, if you want to see if it will fit in your integer or 4 byte number here's a test program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <limits>

int main ()
{
	int MAX = std::numeric_limits<int>::max();
	std::cout << "The maximum size of an integer on this machine is " << sizeof(int) << " and the maximum value it can hold is " << MAX << std::endl;
	if ( MAX >= 0x07070707 || 0x07070707 < 0 )
		std::cout << "The hex number 0x07070707 which is " << long(0x07070707) << " in decimal is smaller than an integer on this machine." << std::endl;
	else
		std::cout << "The hex number 0x07070707 which is " << long(0x07070707) << " does not fit into an integer on this machine.";

	return 0;
}

Topic archived. No new replies allowed.