Bit Field Packer Calculator
Enter each value and its bit width to pack them into one integer.
Result
How it is calculated
Up to three non-negative whole numbers are placed side by side in one integer, with field 1 in the highest bits and field 3 in the lowest: packed = (v1 << (w2 + w3)) | (v2 << w3) | v3. Each w is the number of bits reserved for that field, and each value must be smaller than 2w, otherwise there is no result. Field 3 is optional: if left empty, both its value and its width count as 0. Decimals are cut off to whole numbers, and negative values or widths give no result. The sum of the widths must be between 1 and 63 bits. The packed result is shown in decimal, in hexadecimal and in binary padded to the total width.
Worked example
This is the RGB565 layout for a 16-bit pixel: red 21 in 5 bits, green 42 in 6 bits, blue 10 in 5 bits. Total width: 5 + 6 + 5 = 16 bits. Red moves left by 6 + 5 = 11 bits (21 × 2048 = 43,008). Green moves left by 5 bits (42 × 32 = 1,344). Blue stays as 10. The sum is 43,008 + 1,344 + 10 = 44,362. The tool shows the packed value in three forms, one per line (decimal, hexadecimal, binary): 44,362 0xAD4A 0b1010110101001010
Common mistakes
- Entering a value too large for its width. A 5-bit field holds 0 to 31, so 32 gives no result; widen the field or check the value.
- Expecting field 1 to be in the lowest bits. Field 1 is the most significant part, so the order of the fields on the screen is the order from the high bit down.
- Typing the width as the maximum value (31 instead of 5). The width counts bits, not the largest number that fits.
- Entering decimals or negative numbers as signed values. Fractions are truncated and negatives are rejected, so two's-complement fields must be converted to unsigned values first.
- Forgetting the 63-bit limit when packing into a 64-bit register. The total width is capped at 63, and unused fields should be left at width 0 with value 0.
About this calculator
A bit field packs several small integer values into contiguous groups of bits within one larger integer, so that a single 32-bit or 64-bit word can hold, say, a 5-bit value, an 8-bit value, and a 3-bit value all at once instead of using a separate variable — and separate memory — for each. This calculator takes up to three values with their bit widths, shifts each into its position, ORs them together, and shows the combined result in decimal, hexadecimal, and binary.
Bit-field packing is everywhere in low-level programming: hardware peripheral configuration registers on microcontrollers assign specific bit ranges to specific settings, network protocol headers (like IPv4’s version/IHL byte or TCP flags) pack multiple fields into a few bytes to minimize overhead, and graphics formats like RGB565 pack red, green, and blue channels into a single 16-bit pixel value. Embedded systems and driver developers use exactly this kind of packing to read and write hardware registers correctly.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
When you build a register value from a datasheet, work from the top. Field 1 here sits in the highest bits, so list the datasheet's fields from the most significant bit down and use a width of 0 for any gap you leave unused at the very end. Also check any reserved bits in the middle of the register: this tool has no place for them, so add them as a field with value 0. What register or protocol header are you packing?