Click here to Skip to main content
15,886,963 members
Home / Discussions / C#
   

C#

 
AnswerRe: How do you find value of bits in byte Pin
Mirko198020-Jul-09 23:43
Mirko198020-Jul-09 23:43 
GeneralRe: How do you find value of bits in byte Pin
gwithey21-Jul-09 0:30
gwithey21-Jul-09 0:30 
GeneralRe: How do you find value of bits in byte Pin
gwithey21-Jul-09 0:44
gwithey21-Jul-09 0:44 
AnswerRe: How do you find value of bits in byte Pin
monstale20-Jul-09 23:47
monstale20-Jul-09 23:47 
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 
AnswerRe: How do you find value of bits in byte Pin
DaveyM6921-Jul-09 2:01
professionalDaveyM6921-Jul-09 2:01 
In addition to the excellent advice you've been given - all the Boolean logical operator variants are easy to implement as shown below. Also, using an enum with the Flags attribute can make getting individual bits easier as you can give your enum members more descriptive names.
class Program
{
    static void Main(string[] args)
    {
        byte baseValue = 0x01;
        byte otherValue = 0x07;
        Console.WriteLine("Base Value = {0} : Other Value = {1}", baseValue, otherValue);
        Console.WriteLine("AND result = {0}", baseValue & otherValue);
        Console.WriteLine("OR result = {0}", baseValue | otherValue);
        Console.WriteLine("XOR result = {0}", baseValue ^ otherValue);
        Console.WriteLine("NOT result (Base only) = {0}", (byte)~baseValue);
        Console.WriteLine("NAND result = {0}", (byte)~(baseValue & otherValue));
        Console.WriteLine("NOR result = {0}", (byte)~(baseValue | otherValue));

        Console.WriteLine("Bit0 of Base Value = {0}", baseValue & (byte)Bits.Bit0);
        Console.WriteLine("Bit0 and Bit1 of Other Value = {0}", otherValue & (byte)(Bits.Bit0 | Bits.Bit1));
        Console.ReadKey();
    }
}


[Flags]
public enum Bits : byte
{
    None = 0,
    Bit0 = 1,
    Bit1 = 2,
    Bit2 = 4,
    Bit3 = 8,
    Bit4 = 16,
    Bit5 = 32,
    Bit6 = 64,
    Bit7 = 128
}
If you want to work with binary values directly, unfortunately there is no binary literal in C#. I made this article[^] quite a while ago to make it easier to work with binary strings, you may find it of some use.

Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)

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 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.