Anonymous user
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=>
write: |b -> { b }, { hex_converter=>
result = a bit-and b.
write: |a & b -> { result }, { hex_converter=>
result = a bit-or b.
write: |a \| b -> { result }, { hex_converter=>
result = a bit-xor b.
write: |a ^ b -> { result }, { hex_converter=>
result = bit-not a.
write: |~a -> { result }, { hex_converter=>
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=>
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=>
missing_bitwise_operations=>
exporting
i_value
i_position = b
importing
e_value = result ).
write: |
missing_bitwise_operations=>
exporting
i_value
i_position = b
importing
e_value = result ).
write: |
missing_bitwise_operations=>rotate_left(
Line 358 ⟶ 426:
importing
e_value = result ).
write: |~a rotl b -> { result }, { hex_converter=>
missing_bitwise_operations=>rotate_right(
Line 366 ⟶ 434:
importing
e_value = result ).
write: |a rotr b -> { result }, { hex_converter=>
</lang>
{{output}}
<pre>
a -> 000000FF, 00000000000000000000000011111111, 255
b -> 00000002, 00000000000000000000000000000010, 2
a & b -> 00000002,
a b -> 000000FF,
a ^ b -> 000000FD,
~a -> FFFFFF00,
~a << b -> FFFFFC00, 11111111111111111111110000000000, -1024
~a >> b -> FFFFFFC0, 11111111111111111111111111000000, -64
a <<< b -> 000003FC, 00000000000000000000001111111100, 1020
a >>> b -> 0000003F, 00000000000000000000000000111111, 63
~a rotl b -> FFFFFC03,
a rotr b -> C000003F,
</pre>
|