!**********************************************************************
!* Bit Manipulation Functions - AND/OR/XOR *
!**********************************************************************
!* *
!* INPUT: $I_op - Operation - AND / OR / XOR *
!* $I_mask - Input Binary String 1 (Mask) *
!* $I_string - Input Binary String 2 (Object) *
!* OUTPUT: $O_string - Output Binary String *
!* *
!* To de-activate this function: *
!* #define BIT_Func_Remove *
!* *
!**********************************************************************
!* *
!* EXAMPLE: do BIT-Func('XOR', '01100001', '00100000', $res_xor) *
!* do BIT-Func('AND', '00001111', '01010101', $res_and) *
!* do BIT-Func('OR', '10101010', '01010101', $res_or) *
!* *
!* RESULTS: $res_xor = '01000001' *
!* $res_and = '00000101' *
!* $res_or = '11111111' *
!* *
!* BIT Operation Properties (Bit Results) *
!* ==================================================== *
!* *
!* Operation: (XOR) (AND) (OR) *
!* Mask: 0 0 1 1 0 0 1 1 0 0 1 1 *
!* Object: 0 1 0 1 0 1 0 1 0 1 0 1 *
!* ---------- ------- ------- ------- *
!* Result: 0 1 1 0 0 0 0 1 0 1 1 1 *
!* *
!**********************************************************************
#ifndef BIT_Func_Remove
begin-procedure BIT-Func($I_op, $I_mask, $I_string, :$O_string)
uppercase $I_op
! Synchronize Lengths (Mask/String)
let #len = length($I_mask)
let #len2 = length($I_string)
if #len < #len2
let #len = #len2
end-if
let $I_mask = lpad($I_mask, #len,'0')
let $I_string = lpad($I_string,#len,'0')
! Perform Requested Operation
let $O_string = ''
let #ctr = 1
while #ctr <= #len
let $bit1 = substr($I_mask, #ctr,1)
let $bit2 = substr($I_string,#ctr,1)
evaluate $I_op
when = 'XOR'
let $res = '1'
if $bit1 = $bit2
let $res = '0'
end-if
break
when = 'OR'
let $res = '0'
if $bit1 = '1'
or $bit2 = '1'
let $res = '1'
end-if
break
when = 'AND'
let $res = $bit2
if $bit1 = '0'
let $res = '0'
end-if
break
when-other
let $res = ''
end-evaluate
let $O_string = $O_string || $res
let #ctr = #ctr + 1
end-while
end-procedure
#endif
!**********************************************************************
|