When I tried to convert byte to bits using var bits = Convert.ToString(tmp, 2);
tmp
is a byte values 33 for example. Now the bits
is string '100001', how should I get every single bit value of bits
? For example if(bits[0] == 1) ...do something
Asked
Active
Viewed 575 times
0

Petter Friberg
- 21,252
- 9
- 60
- 109

BarryLib
- 299
- 1
- 5
- 20
-
This question already has an answer here: https://stackoverflow.com/questions/11204666/converting-c-sharp-byte-to-bitarray – Palle Due Jul 06 '17 at 07:04
-
1If `bits` is a `string`, you probably want to compare to a `char` value: `if (bits[0] == '1')`. However, you don't even need to do this, as you can simply access bits in the initial integer variable: `if ((tmp & 0x0001) != 0)`, similar to what you would do in C, Java or other C-like languages. – vgru Jul 06 '17 at 07:07
-
@Groo Thanks, It's the same as C and it works fine! – BarryLib Jul 06 '17 at 07:17