I have a running OpenCL kernel. How can I check if a bit at a selected position in a variable equals to one or not?
For example, I found that in C# we can convert uint
to string containing bits using code like this:
// Here we will store our bit
string bit;
// Unsigned integer that will be converted
uint hex = 0xfffffffe;
// Perform conversion and store our string containing bits
string str = uint2bits(hex);
// Print all bits "11111111111111111111111111111110"
Console.WriteLine(str);
// Now get latest bit from string
bit = str.Substring(31, 1);
// And print it to console
Console.WriteLine(bit);
// This function converts uint to string containing bits
public static string uint2bits(uint x) {
char[] bits = new char[64];
int i = 0;
while (x != 0) {
bits[i++] = (x & 1) == 1 ? '1' : '0';
x >>= 1;
}
Array.Reverse(bits, 0, i);
return new string(bits);
}
How to make inside kernel like in code above?
__kernel void hello(global read_only uint* param) {
/*
Do something with "param"
...
*/
int bit;
int index = 31;
/*
Store bit value ("0" or "1") at variable "bit"
...
*/
if (bit == 1) {
// ...
} else {
// ...
}
// Or maybe something more easy to check a bit value at "index" in "param" ... ?
}
Where I can read more about that?