Page 1 of 1

convert unsigned 64

Posted: 13 Sep 2019 9:26
by Loffy
I know I am missing something simple, but I am having trouble converting an unsigned64 value to an integer.

Any Ideas.

Loffy

Re: convert unsigned 64

Posted: 13 Sep 2019 9:44
by Loffy
Re my post above;

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

Loffy

Re: convert unsigned 64

Posted: 13 Sep 2019 17:00
by Martin Meyer
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).

Re: convert unsigned 64

Posted: 14 Sep 2019 8:05
by Loffy
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

Re: convert unsigned 64

Posted: 14 Sep 2019 8:48
by B.Hooijenga
Tick = time::getTickCount(), %unsigned64
bit::getUnsigned64bytes(Tick, Low, _High),
stdio::write(Low, "\n").

Kind regards
Ben

Re: convert unsigned 64

Posted: 17 Sep 2019 5:46
by Loffy
Thanks to all.

Regards,

Loffy