The code (below) is an output example. Hex output occurs for all the numeric
types but not for unsigned char/char. Does hex only work for numeric values, and
how do I force hex output? cout.setf(ios::hex) does not work.
[code]
using namespace std;
# include <string>
# include <iostream>
# include <iomanip>
int main(int argc, char** argv) {
static const string msg[] = { "r[0] += "
, "r[1] -= "
, "r[2] *= "
, "r[3] /= "
, "r[4] %= "
, "r[5] <<= "
, "r[6] >>= "
, "r[7] &= "
, "r[8] |= "
, "r[9] ^= "
};
static char const a = 254;
char x = 3;
char r[] = { a, a, a, a, a, a, a, a, a, a};
r[0] += x;
r[1] -= x;
r[2] *= x;
r[3] /= x;
r[4] %= x;
r[5] <<= x;
r[6] >>= x;
r[7] &= x;
r[8] |= x;
r[9] ^= x;
cout.setf ( ios::hex, ios::basefield ); // set hex as the basefield
for (int i = 0; i < 10; i++)
cout << msg[i]
<< " 0x" << hex << setfill('0') << x
<< " 0x" << hex << setfill('0') << r[i] << '\n';
}
[/code]
[output]
r[0] += 0x 0x
r[1] -= 0x 0xû
r[2] *= 0x 0xú
r[3] /= 0x 0x
r[4] %= 0x 0xþ
r[5] <<= 0x 0xð
r[6] >>= 0x 0xÿ
r[7] &= 0x 0x
r[8] |= 0x 0xÿ
r[9] ^= 0x 0xý
[/output]
[Linux C Programming]
[Linux Kernel]
[eCos]
[Fedora Development]
[Fedora Announce]
[Autoconf]
[The DWARVES Debugging Tools]
[Yosemite Campsites]
[Yosemite News]
[Linux GCC]