Category:Jq/bitwise.jq: Difference between revisions

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