I perform a ByteOut = bit::bitXor(Byte1, Byte2) operation where both Byte1 and Byte2 are defined as unsigned8.
The resulting ByteOut value is an unsigned32 value.
Is there a better way to make ByteOut an unsigned8 other than using bit::setHigh / setLow predicates to convert between unsigned32 and unsigned8 values when using the bit class operations?
Regards,
Loffy
-
- VIP Member
- Posts: 331
- Joined: 14 Nov 2002 0:01
Re: unsigned8 bit operations
Yes, there is a better way. Just make sure that ByteOut has domain unsigned8:
Or, without hasDomain/2, by a predicate declaration:
Also check Bitwise and boolean operators.
Code: Select all
open core
clauses
run() :-
hasDomain(unsigned8, Byte1),
hasDomain(unsigned8, Byte2),
Byte1 = 1 * 0x04 + 0 * 0x02 + 1 * 0x01,
Byte2 = 1 * 0x04 + 1 * 0x02 + 0 * 0x01,
hasDomain(unsigned8, ByteOut),
ByteOut = Byte1 ^^ Byte2,
stdIO::writeF('%02x', ByteOut).
Code: Select all
open core
class predicates
myXor : (unsigned8 Byte1, unsigned8 Byte2) -> unsigned8 ByteOut.
clauses
myXor(Byte1, Byte2) = Byte1 ^^ Byte2.
clauses
run() :-
Byte1 = 1 * 0x04 + 0 * 0x02 + 1 * 0x01,
Byte2 = 1 * 0x04 + 1 * 0x02 + 0 * 0x01,
ByteOut = myXor(Byte1, Byte2),
stdIO::writeF('%02x', ByteOut).
Regards Martin
Re: unsigned8 bit operations
Martin,
Thanks.
Loffy
Thanks.
Loffy
- Thomas Linder Puls
- VIP Member
- Posts: 1424
- Joined: 28 Feb 2000 0:01
Re: unsigned8 bit operations
This works fine:
Code: Select all
BX = hasDomain(unsigned8, B1 ^^ B2),
Regards Thomas Linder Puls
PDC
PDC