Author Topic: Equivalent of PB HI() and LO() functions  (Read 139 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 223
Equivalent of PB HI() and LO() functions
« on: November 09, 2018, 06:10:26 AM »
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









Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 645
    • Charles Pegge
Re: Equivalent of PB HI() and LO() functions
« Reply #1 on: November 09, 2018, 03:56:54 PM »
Hi Chris,

We already have some defined as core macros:

Code: [Select]
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.

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 223
Re: Equivalent of PB HI() and LO() functions
« Reply #2 on: November 09, 2018, 04:30:18 PM »
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)  ?

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 645
    • Charles Pegge
Re: Equivalent of PB HI() and LO() functions
« Reply #3 on: November 09, 2018, 05:48:29 PM »
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 :)

« Last Edit: November 09, 2018, 05:52:12 PM by Charles Pegge »

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1997
    • www.zapsolution.com
Re: Equivalent of PB HI() and LO() functions
« Reply #4 on: November 09, 2018, 07:18:31 PM »
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

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 645
    • Charles Pegge
Re: Equivalent of PB HI() and LO() functions
« Reply #5 on: November 09, 2018, 07:44:58 PM »
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.

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 223
Re: Equivalent of PB HI() and LO() functions
« Reply #6 on: November 10, 2018, 06:32:40 AM »
Thanxx a lot Charles and Patrice

Offline Brian Alvarez

  • Jr. Member
  • **
  • Posts: 92
    • PluriBASIC
Re: Equivalent of PB HI() and LO() functions
« Reply #7 on: Today at 07:34:42 PM »
I need to emulate HIINT, how can i cast it?

Code: [Select]
def hiintHIINT(((%1)>>32) and 0xffffffff) ' doesnt work
print str(hiint(221134)) ' returns 2221134