Hello. I need to read bits from bytes in a file. I have code that works but it's very slow. Can anybody help me? The code I have is: private bool GetBit(byte b, int pos) { return ((b & (byte)(1 << pos)) != 0); } private int...
See more »
Hello. I need to read bits from bytes in a file. I have code that works but it's very slow. Can anybody help me? The code I have is: private bool GetBit(byte b, int pos) { return ((b & (byte)(1 << pos)) != 0); } private int GetBits(byte b, int offset, int count) { int number = 0; for (int i = 1; i <= count; i++) { if (GetBit(b, offset + i - 1)) { switch (i) { case 1: number += 1; break; case 2: number += 2; break; case 3: number += 4; break; case 4: number += 8; break; case 5: number += 16; break; case 6: number += 32; break; case 7: number += 64; break; case 8: number += 128; break; } } } return number; } Thank you in advance! Oyvind Eriksen
See less »
Kaboodle will send you a newsletter and updates from your friends. You can unsubscribe at any time. Kaboodle does not sell or share your email address or personal information with anyone.
Kaboodle requires all users to provide their real date of birth as both a safety precaution and as a means
of preserving the integrity of the site. You will be able to hide this information from your profile if you wish.
Added by 1 people