Multiple states judged by bit operations in C #

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacestatemachine{classProgram {Static voidMain (string[] args) {            //output decimal-binary ValueConsole.WriteLine (State.a +" - "+ Program.twonum (convert.tostring (State.a,2))); Console.WriteLine (state.b+" - "+ Program.twonum (convert.tostring (state.b,2))); Console.WriteLine (state.c+" - "+ Program.twonum (convert.tostring (state.c,2))); //Create a variable, add three states             ShortMark =0; Mark|=State.a; Mark|=state.b; Mark|=state.c; Console.WriteLine ("\ n"); Console.WriteLine ("Mark's value:"+ Mark +" - "+ Program.twonum (convert.tostring (Mark,2))); Console.WriteLine ("\ n Status Display"); //judge a value in a total of several States            if(Mark & State.a) >0) Console.WriteLine ("have a status of a"); if(Mark & state.b) >0) Console.WriteLine ("have the status of B"); if(Mark & state.c) >0) Console.WriteLine ("have the status of C"); if(Mark & STATE.D) >0) Console.WriteLine ("have the status of D");        Console.ReadLine (); }        //by default, the following 7 0         Public Static stringTwonum (strings) {stringtemp ="";  for(inti = s.length; I <8; i++) {Temp+="0"; } s= S.insert (0, temp); returns; }    }    /// <summary>    ///Status/// </summary>     Public classState { Public Static  ShortA =1<<0;  Public Static  ShortB =1<<1;  Public Static  ShortC =1<<2;  Public Static  ShortB1<<3;  Public Static  ShortE =1<<4; }}

Multiple states judged by bit operations in C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.