Category:Jq/bitwise.jq: Difference between revisions
Content deleted Content added
fix bug in flip/1 |
flip/1 was buggy; fix and flip its input and arg |
||
Line 1: | Line 1: | ||
NEWS: 2024.04.06 - flip/1 |
|||
<syntaxhighlight lang="jq"> |
<syntaxhighlight lang="jq"> |
||
module { |
module { |
||
"name": "bitwise", |
"name": "bitwise", |
||
"description": "bit arrays, bit streams, and integers", |
"description": "bit arrays, bit streams, and integers", |
||
"version": "2024.04. |
"version": "2024.04.06", |
||
"homepage": "https://rosettacode.org/w/index.php?title=Category:Jq/bitwise.jq", |
"homepage": "https://rosettacode.org/w/index.php?title=Category:Jq/bitwise.jq", |
||
"license": "MIT", |
"license": "MIT", |
||
Line 47: | Line 49: | ||
end ; |
end ; |
||
# If |
# If $n is null, then the bitwise bits of the input integer are simply flipped; |
||
# otherwise, |
# otherwise, $n, which should be non-negative, determines the width for padding or truncation |
||
def flip($ |
def flip($n): |
||
if |
if $n == null then stream_to_integer(flipbits(bitwise)) |
||
else |
else [limit($n; bitwise)] as $bits |
||
| stream_to_integer(flipbits( $bits[], (range(0; $n - ($bits|length)) | 0))) |
|||
end; |
end; |
||