Results 1 to 3 of 3

Thread: How to convert array of cl_uint into array of cl_uchar in C++?

  1. #1
    Newbie
    Join Date
    Jul 2013
    Posts
    4

    Question How to convert array of cl_uint into array of cl_uchar in C++?

    Hi,

    I'd like to cast array of cl_uint into array of cl_uchar in C++.

    How can I do that?

    Regards,
    Pit

  2. #2
    Newbie
    Join Date
    Jul 2013
    Posts
    2
    Quote Originally Posted by python View Post
    Hi,

    I'd like to cast array of cl_uint into array of cl_uchar in C++.

    How can I do that?

    Regards,
    Pit
    When you say cast the array what exactly do you mean? Someone correct me if I'm wrong but I believe that cl_uint and cl_uchar are basically the same as unsinged int and unsigned char on most systems so you would cast them the same you would any old data type.
    Need a single value?
    Code :
     cl_uchar Value = (cl_uchar)array_of_cl_uint[0];
    Want to cast the whole array? well... you cant really. if you try to just cast it, the data wont line up properly, what you would have to do is copy it something like this,

    Code :
    cl_uint OldData[100];
    cl_uchar NewData[100];
     
    //Fill OldData
     
    for (int i = 0; i < 100; i++)
    {
        NewData[i] = (cl_uchar)(OldData[i]);
    }

    Of course this all assumes that the data in the cl_uints is valid to be shortened to a char with max value of 255.

  3. #3
    Senior Member
    Join Date
    Oct 2012
    Posts
    165
    In Clew on Windows, cl_uint is 32 bit, cl_uchar is 8 bit. Do you want to reinterpret your uint as 4 uchar? or just one uint to 1 uchar?
    if you want to interpret one uint as 4 uchar the easiest way would be a c style cast i think. If the compiler argus about this, a memcpy could help maybe.
    If you want to interpret one uint as one uchar, the iteration might be the only way to solve that i think.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •