How to use the Binary Word size Converter tool
- Enter the bits in the Binary word field.
- Enter the number of bits you want in the Target word size field, from 1 to 4096.
- Select Resize. The Result box shows the pattern at exactly the target length.
- Select Copy to take the resized word, or Example to pad 10110011 to 16 bits.
What resizing a binary word does
Registers, protocol fields and integer types have fixed widths, and a value often has to move between them. Going to a wider word is zero extension: new bits are added on the left and set to 0, which leaves an unsigned value unchanged.
Going to a narrower word is truncation: the high-order bits are cut off and the rightmost bits survive. Numerically that is the value modulo 2^n for a target of n bits, the same result as a cast to a smaller unsigned type or an AND with a mask of n ones.
Worked example: padding and truncating
The sample word 10110011 is 179. Resized to 16 bits it gains eight zeros on the left and is still 179. Resized to 4 bits only the low nibble 0011 remains, which is 3, and 179 modulo 16 is indeed 3.
10110011, size 16 -> 0000000010110011
10110011, size 4 -> 0011
110100101111, size 8 -> 00101111
1, size 8 -> 00000001Unsigned only: no sign extension
The tool always pads with zeros. That is correct for unsigned data and for positive signed values, but it is wrong for a negative two's complement number. The 8-bit word 11010111 is -41. Padded here to 16 bits it becomes 0000000011010111, which is +215.
Proper sign extension copies the top bit into the new positions, giving 1111111111010111. If your word is signed and negative, prepend ones by hand instead of using the padding from this tool.
Limits and error messages
The two fields have different limits, and truncation happens without a warning, so compare lengths if losing bits would matter.
- The Binary word may be 1 to 65,536 bits. Spaces are ignored and one leading 0b is removed.
- The Target word size must be a whole number from 1 to 4096. Zero, fractions, larger values and an empty field are refused.
- The size error reads: Word size must be a whole number from 1 to 4096.
- Any target is allowed, not only 8, 16, 32 and 64. Sizes such as 12 or 24 work the same way.
- A target equal to the input length returns the input with whitespace removed.
Frequently asked questions
Does the converter sign-extend negative numbers?
No. It treats the input as unsigned and fills new positions with zeros. A negative two's complement word needs ones on the left, which you have to add yourself.
Which bits are removed when the target is smaller than the input?
The leftmost, most significant bits are removed. The tool keeps the last n digits of the input, where n is the target size. For 110100101111 and a size of 8, the result is 00101111.
What is the largest word size I can choose?
4,096 bits. The input itself may be longer, up to 65,536 bits, in which case it is cut down to the target size.
How do I pad a binary number to 8, 16 or 32 bits?
Type the number in the Binary word field, type 8, 16 or 32 in the Target word size field and select Resize. Zeros are added on the left until the word has that many bits.
Will I be told if truncation loses set bits?
No. The result is returned without a notice even when 1 bits were dropped. If that matters, check that the removed part of your input contained only zeros.