Jump to content

Bitwise operations: Difference between revisions

→‎{{header|J}}: Added functions to complete expanded requirements.
(→‎{{header|C}}: small correction)
(→‎{{header|J}}: Added functions to complete expanded requirements.)
Line 158:
 
=={{header|J}}==
{{incorrect|J}}
Actual bitwise calculation occurs in<tt> bwo</tt>. Other definitions provide formatting.
bwo =: 17 b. , 23 b. , 22 b. , 28 b., 33 b.~, (33 b.~ -), (34 b.~ -), 32 b.~, (32 b.~ -)
bwotxt =: title"_ combine bwo
combine =: [ ,. ":@|:@,:@]
titlet =:. >;._2 'Bitwise x AND y: |Bitwise x OR y:|Bitwise x XOR y:|Bitwise NOT-x:|'
title=: t,>;._2'Left shift:|Right shift:|Right signed shift:|Left rotate:|Right rotate:|'
f =: (32#2)&#: { '.x'"_
Examples of execution, with output:
255_255 bwo 1705 NB. numeric output
1 _251 _252 254 _8160 134217720 _8 _8129 268435448
170 255 85 _256
255_255 bwotxt 1705 NB. formatted text with English titling
Bitwise x AND y: 170 1
Bitwise x OR y: 255 _251
Bitwise x XOR y: 85 _252
Bitwise NOT-x: _256 254
Left shift: f 255 bwo 170 NB. 32-bit diagram_8160
Right shift: 134217720
........................x.x.x.x.
Right signed shift: _8
........................xxxxxxxx
Left rotate: _8129
.........................x.x.x.x
Right rotate: 268435448
xxxxxxxxxxxxxxxxxxxxxxxx........
f _255 bwo 5 NB. 32-bit diagram
........................x.x.x.x....x
xxxxxxxxxxxxxxxxxxxxxxxx.....x.x
xxxxxxxxxxxxxxxxxxxxxxxx......x..
........................xxxxxxxxxxxxxxx.
xxxxxxxxxxxxxxxxxxx.......x.....
.....xxxxxxxxxxxxxxxxxxxxxxxx...
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
xxxxxxxxxxxxxxxxxxx.......xxxxxx
....xxxxxxxxxxxxxxxxxxxxxxxxx...
 
=={{header|Java}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.