Jump to content

Bitwise operations: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 210:
public section.
class-methods:
logical_shift_left
importing
i_value type x
i_position type x
exporting
e_value type x,
 
logical_shift_right
importing
i_value type x
i_position type x
exporting
e_value type x,
 
arithmetic_shift_left
importing
Line 252 ⟶ 266:
 
e_value = i_value div 2 ** i_position.
endmethod.
 
 
method logical_shift_left.
clear e_value.
 
data(bits) = hex_converter=>to_binary( i_value ).
 
data(length_of_bit_sequence) = strlen( bits ).
 
bits = shift_left(
val = bits
places = i_position ).
 
while strlen( bits ) < length_of_bit_sequence.
bits = bits && `0`.
endwhile.
 
do strlen( bits ) times.
data(index) = sy-index - 1.
 
data(current_bit) = bits+index(1).
 
if current_bit eq `1`.
set bit sy-index of e_value.
endif.
enddo.
endmethod.
 
 
method logical_shift_right.
clear e_value.
 
data(bits) = hex_converter=>to_binary( i_value ).
 
data(length_of_bit_sequence) = strlen( bits ).
 
bits = shift_right(
val = bits
places = i_position ).
 
while strlen( bits ) < length_of_bit_sequence.
bits = `0` && bits.
endwhile.
 
do strlen( bits ) times.
data(index) = sy-index - 1.
 
data(current_bit) = bits+index(1).
 
if current_bit eq `1`.
set bit sy-index of e_value.
endif.
enddo.
endmethod.
 
Line 304 ⟶ 372:
result type x length 4.
 
write: |a -> { a }, { hex_converter=>to_decimalto_binary( a ) }, { hex_converter=>to_binaryto_decimal( a ) }|, /.
 
write: |b -> { b }, { hex_converter=>to_decimalto_binary( b ) }, { hex_converter=>to_binaryto_decimal( b ) }|, /.
 
result = a bit-and b.
write: |a & b -> { result }, { hex_converter=>to_decimalto_binary( result ) }, { hex_converter=>to_binaryto_decimal( result ) }|, /.
 
result = a bit-or b.
write: |a \| b -> { result }, { hex_converter=>to_decimalto_binary( result ) }, { hex_converter=>to_binaryto_decimal( result ) }|, /.
 
result = a bit-xor b.
write: |a ^ b -> { result }, { hex_converter=>to_decimalto_binary( result ) }, { hex_converter=>to_binaryto_decimal( result ) }|, /.
 
result = bit-not a.
write: |~a -> { result }, { hex_converter=>to_decimalto_binary( result ) }, { hex_converter=>to_binaryto_decimal( result ) }|, /.
 
missing_bitwise_operations=>arithmetic_shift_left(
exporting
i_value = bit-not a
i_position = b
importing
e_value = result ).
write: |~a << b -> { result }, { hex_converter=>to_decimalto_binary( result ) }, { hex_converter=>to_binaryto_decimal( result ) }|, /.
 
missing_bitwise_operations=>arithmetic_shift_right(
exporting
i_value = bit-not a
i_position = b
importing
e_value = result ).
write: |~a >> b -> { result }, { hex_converter=>to_decimalto_binary( result ) }, { hex_converter=>to_binaryto_decimal( result ) }|, /.
 
missing_bitwise_operations=>arithmetic_shift_leftlogical_shift_left(
exporting
i_value = bit-not = a
i_position = b
importing
e_value = result ).
write: |~a <<< b -> { result }, { hex_converter=>to_decimalto_binary( result ) }, { hex_converter=>to_binaryto_decimal( result ) }|, /.
 
missing_bitwise_operations=>arithmetic_shift_rightlogical_shift_right(
exporting
i_value = bit-not = a
i_position = b
importing
e_value = result ).
write: |~a >>> b -> { result }, { hex_converter=>to_decimalto_binary( result ) }, { hex_converter=>to_binaryto_decimal( result ) }|, /.
 
missing_bitwise_operations=>rotate_left(
Line 358 ⟶ 426:
importing
e_value = result ).
write: |~a rotl b -> { result }, { hex_converter=>to_decimalto_binary( result ) }, { hex_converter=>to_binaryto_decimal( result ) }|, /.
 
missing_bitwise_operations=>rotate_right(
Line 366 ⟶ 434:
importing
e_value = result ).
write: |a rotr b -> { result }, { hex_converter=>to_decimalto_binary( result ) }, { hex_converter=>to_binaryto_decimal( result ) }|, /.
</lang>
 
{{output}}
<pre>
a -> 000000FF, 00000000000000000000000011111111, 255
a -> 000000FF, 255, 00000000000000000000000011111111
 
b -> 00000002, 00000000000000000000000000000010, 2
b -> 00000002, 2, 00000000000000000000000000000010
 
a & b -> 00000002, 200000000000000000000000000000010, 000000000000000000000000000000102
 
a b -> 000000FF, 25500000000000000000000000011111111, 00000000000000000000000011111111255
 
a ^ b -> 000000FD, 25300000000000000000000000011111101, 00000000000000000000000011111101253
 
~a -> FFFFFF00, -25611111111111111111111111100000000, 11111111111111111111111100000000-256
 
~a << b -> FFFFFC00, 11111111111111111111110000000000, -1024
a << b -> 000003FC, 1020, 00000000000000000000001111111100
 
~a >> b -> FFFFFFC0, 11111111111111111111111111000000, -64
a >> b -> 0000003F, 63, 00000000000000000000000000111111
 
a <<< b -> 000003FC, 00000000000000000000001111111100, 1020
~a <<< b -> FFFFFC00, -1024, 11111111111111111111110000000000
 
a >>> b -> 0000003F, 00000000000000000000000000111111, 63
~a >>> b -> FFFFFFC0, -64, 11111111111111111111111111000000
 
~a rotl b -> FFFFFC03, -102111111111111111111111110000000011, 11111111111111111111110000000011-1021
 
a rotr b -> C000003F, -107374176111000000000000000000000000111111, 11000000000000000000000000111111-1073741761
</pre>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.