Bit Segment Structure

Source: Internet
Author: User

The length of the bucket occupied by members in the struct (or shared body) is defined in units of bits.
The struct type containing bits is called the bits structure.

The bitwise structure is also a struct type, except that it contains a member of the integer type that defines the storage length in bits. The bit segment structure can save both storage space and facilitate operations.

The Definition Format of the median segment in the bit segment structure is as follows:
Unsigned <member name >:< binary digits>
For example:
Struct bytedata
{Unsigned A: 2;/* segment A, which occupies 2 places */
Unsigned: 6;/* unsigned segment, which occupies 6 digits, but cannot be accessed */
Unsigned: 0;/* the unsigned segment, which occupies 0. The next segment of the table starts from the bottom boundary */
Unsigned B: 10;/* segment B, which occupies 10 digits */
Int I;/* Member I, starting from the bottom boundary */
} Data;

Reference of bit segment data:
It is the same as the data reference in the structure member. However, you must note that the maximum value range of the bit segment should not be greater than the value range specified by the binary number. Otherwise, the excess part will be discarded.
For example, data. A = 2; but data. A = 10; is out of the range (A occupies 2 places, up to 3)

Pay attention to the following points for BIT data:

(1) A single segment must be stored in the same storage unit (Word) and cannot be stored across two units. If the unit space is not enough, the remaining space is not used. This segment is stored from the next unit.
(2) The next segment can start from the next storage unit by defining a bit segment with a length of 0.
(3) An anonymous segment can be defined.
(4) The length of the bit segment cannot exceed the length of the storage unit.
(5) The bitwise segment does not have an address, and the bitwise segment cannot be used for address fetch operations.
(6) Bit segments can be output in % d, % O, % x format.
(7) If the bits appear in the expression, the system automatically converts them to integers.

 

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.