Page 1 of 1
unsigned8 bit operations
Posted: 7 Sep 2019 13:48
by Loffy
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
Re: unsigned8 bit operations
Posted: 7 Sep 2019 17:28
by Martin Meyer
Yes, there is a better way. Just make sure that
ByteOut has domain
unsigned8:
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).
Or, without
hasDomain/2, by a predicate declaration:
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).
Also check
Bitwise and boolean operators.
Re: unsigned8 bit operations
Posted: 8 Sep 2019 5:09
by Loffy
Martin,
Thanks.
Loffy
Re: unsigned8 bit operations
Posted: 9 Sep 2019 8:29
by Thomas Linder Puls
This works fine:
Code: Select all
BX = hasDomain(unsigned8, B1 ^^ B2),