Definition: | object res = shift_bits(object source_number, integer shift_distance) |
Description: |
Moves the bits in the input value by the specified distance.
source_number: The value(s) whose bits will be be moved. shift_distance: number of bits to be moved by. Returns: atom(s) containing a 32-bit integer. A single atom in source_number yields a single atom result, otherwise the result is a sequence with the same shape as source_number, consisting of 32-bit integers. |
Comments: |
If source_number is a sequence, each element is shifted. The value(s) in source_number are first truncated to a 32-bit integer. The output is truncated to a 32-bit integer. Vacated bits are replaced with zero. If shift_distance is negative, the bits in source_number are moved left. If shift_distance is positive, the bits in source_number are moved right. If shift_distance is zero, the bits in source_number are not moved. |
Example: |
?shift_bits(7,-3) --==> 56 (==7*8) ?shift_bits(0,-9) --==> 0 ?shift_bits(4,-7) --==> 512 (==4*128) ?shift_bits(8,-4) --==> 128 (==8*16) ?shift_bits(0xFE427AAC,-7) --==> 557667840 (==0x213D5600) ?shift_bits(0xFE427AAC,-8) --==> 1115335680 (==#427AAC00) ?shift_bits(-7,-3) --==> -56 (==0xFFFFFFC8) ?shift_bits(131,0) --==> 131 ?shift_bits(184.464,0) --==> 184 ?shift_bits(999_999_999_999_999,0) --==> -1530494977 (==0xA4C67FFF) ?shift_bits(184,3) --==> 23 (==184/8) ?shift_bits(48,2) --==> 12 (==48/4) ?shift_bits(121,3) --==> 15 (==floor(121/8)) ?shift_bits(0xFE427AAC, 7) --==> 33326325 (==0x01FC84F5) ?shift_bits(-7,3) --==> 536870911 (==0x1FFFFFFF) ?shift_bits({48,121},2) --==> {12,30} |