Click here to Skip to main content
15,901,505 members
Home / Discussions / C#
   

C#

 
GeneralRe: How do you find value of bits in byte Pin
gwithey21-Jul-09 0:20
gwithey21-Jul-09 0:20 
GeneralRe: How do you find value of bits in byte Pin
monstale21-Jul-09 0:53
monstale21-Jul-09 0:53 
AnswerRe: How do you find value of bits in byte Pin
0x3c020-Jul-09 23:51
0x3c020-Jul-09 23:51 
It's a matter of using ANDs, and other boolean stuff (if you want to read multiple bits). Basically, you use the formula:

bitNSet = (originalInteger & (1 << N) == 1 << N)

Effectively, every integer is represented by a binary sequence. For example, 39 would be represented by 100111. Each one and zero is a bit. To get a bit, you have to AND it, which gets all the bits which are set in both of the numbers given to it. For example, 39 AND 4 would be worked out like so:

100111 AND
000100 =
------
000100

As you can see, you end up with a binary sequence, which is represented by 4 in decimal (base-10). You use the AND against a bit pattern to see if that bit is set. Now, unfortunately, you don't get a true or false value. Note that the result of 39 AND 4 was 4. So, we can apply this further, and say that if q AND n is equal to n, then bit n was set.

Now we just have to get a binary pattern to use against the AND. To get this, we just use the << operator. It will perform a left binary shift on the left operand. So 1 << 5 would result in 100000, 1 << 2 would result in 100, etc. Those numbers are in binary format by the way. So, shifting 1 left by N will give us a binary pattern where only the Nth bit is set. By ANDing that with the original integer, we can check if the bit is set

Between the idea
And the reality
Between the motion
And the act
Falls the Shadow

AnswerRe: How do you find value of bits in byte Pin
DaveyM6921-Jul-09 2:01
professionalDaveyM6921-Jul-09 2:01 
GeneralRe: How do you find value of bits in byte Pin
PIEBALDconsult21-Jul-09 4:18
mvePIEBALDconsult21-Jul-09 4:18 
AnswerRe: How do you find value of bits in byte Pin
Luc Pattyn21-Jul-09 2:05
sitebuilderLuc Pattyn21-Jul-09 2:05 
QuestionHow to find the needless references in a project ? Pin
chenxiang20-Jul-09 19:55
chenxiang20-Jul-09 19:55 
AnswerRe: How to find the needless references in a project ? Pin
stancrm20-Jul-09 20:41
stancrm20-Jul-09 20:41 
QuestionPlay Live Remote IP Cam Video in Windows application Player using C#.Net Pin
vasanth arivali20-Jul-09 19:02
vasanth arivali20-Jul-09 19:02 
AnswerRe: Play Live Remote IP Cam Video in Windows application Player using C#.Net Pin
Jimmanuel21-Jul-09 1:04
Jimmanuel21-Jul-09 1:04 
GeneralType conversion Pin
Mycroft Holmes20-Jul-09 16:46
professionalMycroft Holmes20-Jul-09 16:46 
GeneralRe: Type conversion Pin
harold aptroot20-Jul-09 16:53
harold aptroot20-Jul-09 16:53 
GeneralRe: Type conversion Pin
Mycroft Holmes20-Jul-09 18:11
professionalMycroft Holmes20-Jul-09 18:11 
GeneralRe: Type conversion PinPopular
PIEBALDconsult20-Jul-09 17:10
mvePIEBALDconsult20-Jul-09 17:10 
GeneralRe: Type conversion Pin
Mycroft Holmes20-Jul-09 18:09
professionalMycroft Holmes20-Jul-09 18:09 
GeneralRe: Type conversion Pin
PIEBALDconsult20-Jul-09 19:01
mvePIEBALDconsult20-Jul-09 19:01 
GeneralRe: Type conversion Pin
harold aptroot20-Jul-09 19:06
harold aptroot20-Jul-09 19:06 
GeneralRe: Type conversion Pin
PIEBALDconsult20-Jul-09 19:09
mvePIEBALDconsult20-Jul-09 19:09 
GeneralRe: Type conversion Pin
harold aptroot20-Jul-09 19:24
harold aptroot20-Jul-09 19:24 
QuestionMessage Removed Pin
20-Jul-09 14:19
ImNAM20-Jul-09 14:19 
AnswerRe: Getting Values from List Pin
PIEBALDconsult20-Jul-09 14:21
mvePIEBALDconsult20-Jul-09 14:21 
General[Message Deleted] Pin
ImNAM20-Jul-09 14:23
ImNAM20-Jul-09 14:23 
GeneralRe: Getting Values from List Pin
Christian Graus20-Jul-09 14:24
protectorChristian Graus20-Jul-09 14:24 
AnswerRe: Getting Values from List Pin
Christian Graus20-Jul-09 14:25
protectorChristian Graus20-Jul-09 14:25 
GeneralRe: Getting Values from List Pin
ImNAM20-Jul-09 14:30
ImNAM20-Jul-09 14:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.