Discussions related to Visual Prolog
Loffy
Active Member
Posts: 47
Joined: 15 Aug 2019 11:32

unsigned8 bit operations

Unread post 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
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Re: unsigned8 bit operations

Unread post 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.
Regards Martin
Loffy
Active Member
Posts: 47
Joined: 15 Aug 2019 11:32

Re: unsigned8 bit operations

Unread post by Loffy »

Martin,

Thanks.

Loffy
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Re: unsigned8 bit operations

Unread post by Thomas Linder Puls »

This works fine:

Code: Select all

BX = hasDomain(unsigned8, B1 ^^ B2),
Regards Thomas Linder Puls
PDC
Post Reply