Grouped Ones
All ones are together!
Grouped Ones
Problem Statement
Given a 32-bit binary value, ensure that all 1s are grouped together consecutively. Valid patterns are: all 0s, all 1s, or a block of 1s followed by all 0s.
This constraint ensures that the binary representation follows a "grouped" pattern where 1s never appear on both sides of a 0.
Constraints
- Value size: 32 bits
- Pattern: All 1s must be consecutive (1s cannot have 0s between them)
Examples
Example 1:
0x0000000F
00000000000000000000000000001111
Valid
Explanation: Four consecutive 1s at the end, followed by 0sExample 2:
0xFFFFFFFF
11111111111111111111111111111111
Valid
Explanation: All 1s (completely grouped)Example 3:
0x00000000
00000000000000000000000000000000
Valid
Explanation: All 0s (no 1s to group)Example 4:
0xFF000000
11111111000000000000000000000000
Valid
Explanation: 8 consecutive 1s followed by all 0sExample 5:
0x0F0F0F0F
00001111000011110000111100001111
Invalid
Explanation: 1s are separated by 0s - not grouped togetherExample 6:
0xF0FF0000
11110000111111110000000000000000
Invalid
Explanation: 1s appear on both sides of a 0 block in the middleLoading the interactive workspace...