2

I'm trying to verify my pointers are in place and I'd like to print the value of a cl_uchar (unsigned char OpenCL type) in hex format. I tried:

cout << "Data matrix 0,3 = " << clMatrixPerm->data_matrix->elements[4] << endl;

and

cout << "Data matrix 0,3 = " << hex << clMatrixPerm->data_matrix->elements[4] << endl;

where clMatrixPerm->data_matrix->elements[4] is the data in the array to be printed. In both cases there was no output after Data matrix 0,3 =. I was able to use a workaround with printf so I know the data is being assigned correctly, but I'd like to print it using cout if possible.

John Dibling
  • 99,718
  • 31
  • 186
  • 324
charon00
  • 109
  • 1
  • 5
  • Does casting it to an int type work? – Anthony Dec 02 '11 at 00:40
  • Yes, but I'd like to be able to see it in hex. I tried casting it to unsigned char also, but no success. – charon00 Dec 02 '11 at 00:55
  • 2
    The top answer [given here](http://stackoverflow.com/questions/673240/how-do-i-print-an-unsigned-char-as-hex-in-c-using-ostream) works on my platform for `cl_uchar`. – James Dec 02 '11 at 02:30
  • Thanks James, that worked. I decided to use the solution of casting the data to int and then using the hex cout operator. I think that's what anthony-arnold was getting at but I didn't understand until I looked at your link. – charon00 Dec 02 '11 at 17:13
  • @James You might want to add that as an answer here so it can be accepted and is easy to find for future reference :D – Alexander Varwijk Jul 25 '13 at 17:52

1 Answers1

1

Simple

cout << "Data matrix 0,3 = " << hex << static_cast<unsigned int>(clMatrixPerm->data_matrix->elements[4]) << endl;
user2746401
  • 3,157
  • 2
  • 21
  • 46