convert unsigned 64

Discussions related to Visual Prolog
Loffy
Posts: 22
Joined: 15 Aug 2019 11:32

convert unsigned 64

Unread post by Loffy » 13 Sep 2019 9:26

I know I am missing something simple, but I am having trouble converting an unsigned64 value to an integer.

Any Ideas.

Loffy

Loffy
Posts: 22
Joined: 15 Aug 2019 11:32

Re: convert unsigned 64

Unread post by Loffy » 13 Sep 2019 9:44

Re my post above;

I only need the "Low" 32 of the unsigned64.

Loffy

Martin Meyer
VIP Member
Posts: 283
Joined: 14 Nov 2002 0:01

Re: convert unsigned 64

Unread post by Martin Meyer » 13 Sep 2019 17:00

The result of predicate bit::getLow32of64/1-> has type unsigned.

The value of an unsigned can be represented by an integer only if the value does not exceed the limits of the integer type. That is, convert(integer, U32) cannot work out when the value of the unsigned U32 is greater than upperBound(integer). Maybe this is the reason of your trouble.

I suppose what you want to do, is to reinterpret the four low bytes of the unsigned64 as an integer. This is always possible, but it might be important for your purposes that the four bytes represent different values when interpreted as unsigned or as integer. An example:

Code: Select all

class predicates     convertU64ToInt : (unsigned64 U64) -> integer Int. clauses     convertU64ToInt(U64) = uncheckedConvert(integer, LowU32) :-         LowU32 = bit::getLow32of64(U64).   clauses     run() :-         Int = convertU64ToInt(0xFFFFFFFFFFFFFFFF),         stdIO::write(Int).
Regards Martin

Loffy
Posts: 22
Joined: 15 Aug 2019 11:32

Re: convert unsigned 64

Unread post by Loffy » 14 Sep 2019 8:05

Martin,

Thanks for the insight, though my problem seems to relate to a slightly different issue.

……...
Tick = time::getTickCount, %unsigned64
bit::getUnsigned64bytes(Tick, Low, _High),
……….

If I have the above two lines of code in a counter loop I get the following compile error:

e504 The expression has type '() -> ::unsigned64 procedure', which is incompatible with the type '::unsigned64' TaskWindow.pro TaskWindow\

Regards,

Loffy

B.Hooijenga
VIP Member
Posts: 100
Joined: 11 Jul 2002 23:01

Re: convert unsigned 64

Unread post by B.Hooijenga » 14 Sep 2019 8:48

Tick = time::getTickCount(), %unsigned64
bit::getUnsigned64bytes(Tick, Low, _High),
stdio::write(Low, "\n").

Kind regards
Ben

Loffy
Posts: 22
Joined: 15 Aug 2019 11:32

Re: convert unsigned 64

Unread post by Loffy » 17 Sep 2019 5:46

Thanks to all.

Regards,

Loffy

Post Reply