program in C, I had to convert a character to char to binary and i found this awesome code online...
Although i understand what this line is doing, i want to know if it was just a pattern someone smart noticed or there a reason why this works and i have some knowledge gap?
Code: for(i = 0; i < 8; i++) bits[i] = ((1<<i) & myChar) != 0 ? 1:0;
Read bit fields and bitwise operations
Nothing special tho. These will be in the examples
actually, a char is a binary type, just like everything, the bits[] is just an array where each number is either 1 or 0
bits[i] = (myChar >> i) & 0x1; should also work
Обсуждают сегодня