RosettaCodeData/Task/Set-right-adjacent-bits/00-TASK.txt

52 lines
2.0 KiB
Plaintext

Given a left-to-right ordered collection of <code>e</code> bits, <code>b</code>, where <code>1 <= e <= 10000</code>,
and a zero or more integer <code>n</code> :
* Output the result of setting the <code>n</code> bits to the right of any set bit in <code>b</code>
(if those bits are present in b and therefore also preserving the width, <code>e</code>).
'''Some examples:''' <br>
Set of examples showing how one bit in a nibble gets changed:
n = 2; Width e = 4:
Input b: 1000
Result: 1110
Input b: 0100
Result: 0111
Input b: 0010
Result: 0011
Input b: 0000
Result: 0000
Set of examples with the same input with set bits of varying distance apart:
n = 0; Width e = 66:
Input b: 010000000000100000000010000000010000000100000010000010000100010010
Result: 010000000000100000000010000000010000000100000010000010000100010010
n = 1; Width e = 66:
Input b: 010000000000100000000010000000010000000100000010000010000100010010
Result: 011000000000110000000011000000011000000110000011000011000110011011
n = 2; Width e = 66:
Input b: 010000000000100000000010000000010000000100000010000010000100010010
Result: 011100000000111000000011100000011100000111000011100011100111011111
n = 3; Width e = 66:
Input b: 010000000000100000000010000000010000000100000010000010000100010010
Result: 011110000000111100000011110000011110000111100011110011110111111111
<br>'''Task:'''<br>
* Implement a routine to perform the setting of right-adjacent bits on representations of bits that will scale over the given range of input width <code>e</code>.
* Use it to show, here, the results for the input examples above.
* Print the output aligned in a way that allows easy checking by eye of the binary input vs output.