How to use the Binary Bitfield Converter tool
- Enter the word in the Binary word box, for example 10110011.
- Enter the position of the field's lowest bit in the Bit offset box. Bit 0 is the rightmost bit.
- Enter the number of bits to take in the Field width box.
- Select Extract, or select Example to run 10110011 with offset 2 and width 3.
- Read the extracted bits in the Result box, then select Copy or Clear.
How bit field extraction works
A bit field is a group of adjacent bits inside a larger word that holds one value. Protocol headers, file formats and hardware registers pack several small values into one word this way to save space. To read a field you need two facts: where it starts and how many bits it has.
This tool numbers bits from the right, starting at 0 for the least significant bit. The field covers bits offset through offset + width - 1. In code, the same operation is a right shift followed by a mask: (word >> offset) & ((1 << width) - 1). The tool returns those bits as a binary string, including any leading zeros, so the output always has exactly width digits. A three-bit field of all zeros prints as 000, not as a single 0.
Worked example: an RGB565 pixel
A 16-bit RGB565 pixel stores red in the top 5 bits, green in the middle 6 and blue in the low 5. For the word 1010010111000011, three extractions separate the channels.
The page's own example is smaller. In 10110011, offset 2 with width 3 selects bits 4, 3 and 2, which are 100.
Binary word: 1010010111000011
Bit offset 11, Field width 5 -> 10100 (red, 20)
Bit offset 5, Field width 6 -> 101110 (green, 46)
Bit offset 0, Field width 5 -> 00011 (blue, 3)Limits enforced by the binary bitfield calculator
The field must lie completely inside the word you entered. The tool checks the numbers against the actual word length and tells you the allowed range. The extraction runs in your browser, and the word is not uploaded.
Leading zeros count as part of the word. Entering 0011 gives a four-bit word, and entering 11 gives a two-bit word, so pad the input to the full register width before extracting high fields.
- The word may have 1 to 65,536 binary digits. Spaces and a 0b prefix are removed first.
- Bit offset must be a whole number from 0 to the word length minus 1.
- Field width must be a whole number from 1 to the word length minus the offset.
- The number boxes on the form allow offsets up to 4,095 and widths up to 4,096.
- Out-of-range values produce messages such as Width must be a whole number from 1 to 2.
LSB 0 versus MSB 0 numbering
Datasheets for most microcontrollers number bits the way this tool does, with bit 0 on the right. Network standards often do the opposite. The header diagrams in RFC 791 label the leftmost bit as 0. A field described there as starting at bit 4 with a length of 4 is not at offset 4 here.
To translate, subtract from the word length: offset = length - start - width. In the first byte of an IPv4 header, 01000101, the version field is the left four bits. That is offset 8 - 0 - 4 = 4 with width 4, which returns 0100, version 4. The header length field is offset 0 with width 4 and returns 0101.
Frequently asked questions
How do I extract bits 7 to 4 of a byte?
Enter the eight-bit word, set Bit offset to 4 and Field width to 4, then select Extract. For 10110011 the result is 1011, the upper nibble.
Why do I get a width error?
The field would run past the top of the word. With an 8-bit word and an offset of 6, only bits 6 and 7 remain, so the width can be 1 or 2. Reduce the width or pad the word with leading zeros.
Can I enter the word in hexadecimal?
No. The Binary word box takes binary digits only. Convert the value with the Hexadecimal to Binary tool, pad the result with leading zeros to the full word width, and paste the bits here.
Is the extracted field shown in decimal?
No. The tool returns the field as binary digits. Paste the result into the Binary to Decimal tool if you need the numeric value.