Bitwise AND operation

Could someone provide some background and an explanation of the instructions below?

CPT(INDIRECT_WORD,(INDIRECT_REFERENCE AND 16#FFFFFFF0)/16)
CPT(INDIRECT_BIT,INDIRECT_REFERENCE AND 15)


I think it means:
INDIRECT_WORD = (INDIRECT_REFERENCE AND 16#FFFFFFF0)/16
INDIRECT_BIT= (INDIRECT_REFERENCE AND 15)

What would the expected values for INDIRECT_WORD and INDIRECT_BIT, as INDIRECT_REFERENCE changes from 0 to 50?

What value of INDIRECT_REFERENCE would produce a value of 15 for INDIRECT_WORD?
What value of INDIRECT_REFERENCE would produce a value of 15 for INDIRECT_BIT ?

Other details:
These instructions are from an Add On Instruction.

INDIRECT_REFERENCE is a reference to a T_INT32

Not clear to me how to interpret,
a) 16#FFFFFFF0
b) (INDIRECT_REFERENCE AND 16#FFFFFFF0)/16)
c) INDIRECT_REFERENCE AND 15


Thanks for your help!
 
I cannot say for certain because this is but a code fragment and you do not specify the language but I will make some assumptions and do my best.

The constant expression 16#FFFFFFF0 is a 32 bit constant given in hexadecimal format. The "16#" indicates it is hexadecimal. In hex, an "F" indicates 4 bits that are all set to 1's. There are seven F's and 4 bits per character so there are 28 bits set to 1. The least significant character is 0 which indicates the least significant 4 bits are zero. With the bitwise AND function any of the most significant bits 28 bits in INDIRECT_REFERENCE which are set will remain set in the result and any of the 28 most significant bits that are 0 will remain 0. With the least significant 4 bits of the operation, all those bits in INDIRECT_REFERENCE will be cleared.

However, since the next operation is an integer divide by 16 in decimal, all the bits of the integer expression get shifted to the right by 4 bits. Since the previous bitwise AND operation only changed the least significant 4 bits and those 4 were eliminated by the the divide by 16, the result is to effectively take INDIRECT_REFERENCE and perform and integer divide by 16. As far as what is the result for INDIRECT_REFERENCE for numbers 1 to 50, simply take the number and divide by 16 and that is your result.

For the second line of the code fragment INDIRECT_REFERENCE is being bitwise AND'ed with the number 15 in decimal format. The number 15 in hexadecimal format is "F". Assuming the operation is 32 bit, then the complete hexadecimal format for the number 15 would be 16#0000000F. So the AND operation effectively zeros all bits except the least significant 4 bits. The result of the operation is effectively equivalent to the modulo 16 operation in integer arithmetic. So for numbers 1 to 50, the result provided in INDIRECT_BIT, assuming INDIRECT_BIT is a 32 bit integer will be (in order): 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2.

Hope this helps.
 
I cannot say for certain because this is but a code fragment and you do not specify the language but I will make some assumptions and do my best.

The constant expression 16#FFFFFFF0 is a 32 bit constant given in hexadecimal format. The "16#" indicates it is hexadecimal. In hex, an "F" indicates 4 bits that are all set to 1's. There are seven F's and 4 bits per character so there are 28 bits set to 1. The least significant character is 0 which indicates the least significant 4 bits are zero. With the bitwise AND function any of the most significant bits 28 bits in INDIRECT_REFERENCE which are set will remain set in the result and any of the 28 most significant bits that are 0 will remain 0. With the least significant 4 bits of the operation, all those bits in INDIRECT_REFERENCE will be cleared.

However, since the next operation is an integer divide by 16 in decimal, all the bits of the integer expression get shifted to the right by 4 bits. Since the previous bitwise AND operation only changed the least significant 4 bits and those 4 were eliminated by the the divide by 16, the result is to effectively take INDIRECT_REFERENCE and perform and integer divide by 16. As far as what is the result for INDIRECT_REFERENCE for numbers 1 to 50, simply take the number and divide by 16 and that is your result.

For the second line of the code fragment INDIRECT_REFERENCE is being bitwise AND'ed with the number 15 in decimal format. The number 15 in hexadecimal format is "F". Assuming the operation is 32 bit, then the complete hexadecimal format for the number 15 would be 16#0000000F. So the AND operation effectively zeros all bits except the least significant 4 bits. The result of the operation is effectively equivalent to the modulo 16 operation in integer arithmetic. So for numbers 1 to 50, the result provided in INDIRECT_BIT, assuming INDIRECT_BIT is a 32 bit integer will be (in order): 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2.

Hope this helps.

That does help. Thanks for the clear explanations.
This is for RS Logix5000.

One detail to check,
"As far as what is the result for INDIRECT_REFERENCE for numbers 1 to 50, simply take the number and divide by 16 and that is your result."
since INDIRECT_WORD is a 32 bit integer, only the integer part of the division is retained?
For example, if INDIRECT_REFERNCE is 48, 49, or 50, the result would be 3.

Thanks again,
 
That does help. Thanks for the clear explanations.
This is for RS Logix5000.

One detail to check,
"As far as what is the result for INDIRECT_REFERENCE for numbers 1 to 50, simply take the number and divide by 16 and that is your result."
since INDIRECT_WORD is a 32 bit integer, only the integer part of the division is retained?
For example, if INDIRECT_REFERNCE is 48, 49, or 50, the result would be 3.

Thanks again,
Yes. The result would be 3.
 
Top