Use of bit fields in C language

Source: Internet
Author: User
Through a consortium, you can manage every bit of a byte, so that it saves memory and makes full use of the information in bytes.

The value range of union state{struct Bitdata{bool d0:1;//bool: 0 or -1bool d1:1; The value range of BOOL D2:1;byte d3:1;//byte: 0 or 1byte d4:1;byte d5:1;byte d6:1;byte d7:1;} bit;//must declare a variable byte value;}; void Cmfcapplication1dlg::onbnclickedbutton4 () {state Sta;sta.value = 0x17;//Overall assignment bool A1 = Sta. BIT. d0;//take out the first bit of Sta. BIT. D0 = false;//assigns a value to the first bit//converts the value to a string CString str = sta. BIT. D0? _t ("True"): _t ("False");}

Bit fields are commonly used as device IO State management or rights management. You can actually use arrays instead of the above functions.

Use of bit fields in C language

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.