May 04, 2024, 02:35:27 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


MAKELONG

Started by zaphod, November 09, 2009, 12:50:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

zaphod

Hello,
I have 2 32 bits ints (hiword/loword) and i want to obtain a 64 bits int value : how can i do that ?

sapero

November 09, 2009, 02:34:32 AM #1 Last Edit: November 09, 2009, 02:41:45 AM by sapero
Use a union - fill HI and LO, then read QUAD:
type LARGEINT
int64 quad[0]
int lo
uint hi
endtype

Or with multipliation (may be slower): int64=lo+hi*4294967296q.
With pointer:
int64 value
pointer p = &value
*<int>p[0] = lo
*<uint>p[1] = hi

With a subroutine:
some_sub(lo, hi)

sub some_sub(int lo, uint hi)
  pointer p = &lo
  int64 v = *<int64>p

Ionic Wind Support Team

or just simple math will do it:


int hi=1
int lo=2
int64 i64 = int(hi * 2^32) | lo
print hex$(i64)
Ionic Wind Support Team

Ionic Wind Support Team

Another way using shifts:


int hi=1
int lo=2

int64 i64 = hi
i64 = i64<<16<<16|lo
print hex$(i64)
Ionic Wind Support Team

zaphod

Thanx for responses.
Thats help me for my app...

Ionic Wind Support Team

A cleaner way using shifts:


int hi=1
int lo=2
int64 i64
i64 = (hi+0q)<<16<<16|lo
print hex$(i64)


Which could be made into a very simple function:

sub makelong(int hi,int lo),int64
return (hi+0q)<<16<<16|lo
endsubf
Ionic Wind Support Team