• Welcome to Jose's Read Only Forum 2023.
 

Equivalent of PB HI() and LO() functions

Started by Chris Chancellor, November 09, 2018, 06:10:26 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Chris Chancellor

Hello Charles

in PB they have  HI() and LO() functions  , what would be the equivalent functions in O2 ?

for the HI()  function, you can refer to  http://www.manmrk.net/tutorials/basic/PowerBASIC/PBW10/html/HI_function.html

and the LO() function ,  http://www.manmrk.net/tutorials/basic/PowerBASIC/PBW10/html/LO_function.html

i have converted  PB
HI(WORD,lparam)   

  successfully to  O2
HIWORD(lparam) 


but i'm not sure about  converting  PB 
HI(Integer, wparam)

as there is no equivalent in C++  literature in the internet.

hope that you can give some advice on this

Thanxx









Charles Pegge

Hi Chris,

We already have some defined as core macros:


def lobyte ((%1) and 0xff)
def loword ((%1) and 0xffff)
def hibyte (((%1)>>8) and 0xff)
def hiword (((%1)>>16) and 0xffff)


I think hi(..) lo(..) is not advantageous.

Chris Chancellor

Thanxx a lot Charles

what is the name of the include file which contains these macros ?
so that i can use it

also,

does  HIbyte(wparam)     is  equivalent to  HI(Integer, wparam)  ?

Charles Pegge

#3
They are already available.

All the core language definitions were in source-file: o2keyw.bas, but will be in lang.inc.

hi(int,wParam) doesn't quite make sense to me - since it is dual-platform.

However, if you wanted the upper/lower bits of a 64bit:

def HiDword(((%1)>>32) and 0xffffffff)

def LoDword((%1) and 0xffffffff)


You can invent others :)


Patrice Terrier

I would recommend to use INT rather than DWORD, especially if you are dealing with mouse coordinates, or window locations that could be negative.

#define LOINT(a) ((SHORT)(a))
#define HIINT(a) ((SHORT)(((DWORD)(a) >> 16) & 0xFFFF))
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Charles Pegge

Hi Patrice,

Fortunately, these o2 macros do not interfere with the type-cast or the sign bits, so it would be safe to use them on any type of integer.

Chris Chancellor


Brian Alvarez

#7
I need to emulate HIINT, how can i cast it?

def hiint(((%1)>>32) and 0xffffffff) ' doesnt work
print str(hiint(221134)) ' returns 2221134

Charles Pegge

Hi Brian,

Yes, I see the 32bit shift does not work in 32bit mode

This will work in 64bit mode, but you have to use a quad variable, not a number.


$filename "c.exe"
uses ..\rtl64
def hiint((%1)>>32)
quad a,b
a=0x12345678*0x100
b=hiint(a)
print hex b '12


But this method avoids the bit-shifting problem, and will work on both platforms:


function hiint(quad*q) as int
=============================
int i at @q+4
return i
end function

quad a=0x12345678*0x100
print hex hiint a '12


Brian Alvarez