Date: 02-16-2022
Return to Index
created by gbSnippets
'This shows how to use the Shift function to place
'two smaller values into a larger Long integer. The
'number of bits assigned to each value can be adjusted.
'Primary Code:
'These 3 functions do the work, and are perform the
'same as the PowerBASIC MAK, LO, and HI functions.
Function CustomMak(ValueHi As Long, ValueLo As Long) As Long
Shift Left ValueHi, %bLo
Function = ValueHi + ValueLo
End Function
Function CustomLo(BigValue as long) As Long
Shift Left BigValue, %bHi
Shift Right BigValue, %bHi
Function = BigValue
End Function
Function CustomHi(BigValue As Long) As Long
Shift Right BigValue, %bLo
Function = BigValue
End Function
'In this example, the sign bit of a Long is not used - it works on
'positive values only. Using a DWord would give one more available bit.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
%bHi = 12 : %bLo = 20
Global hDlg as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 101,"Mak", 50,10,100,20
Control Add Button, hDlg, 102,"Lo", 50,40,100,20
Control Add Button, hDlg, 103,"Hi", 50,70,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case 101 : ? str$(CustomMak(2,4))
Case 102 : ? str$(CustomLo(2097156))
Case 103 : ? str$(CustomHi(2097156))
End Select
End Select
End Function
Function CustomMak(ValueHi As Long, ValueLo As Long) As Long
Shift Left ValueHi, %bLo
Function = ValueHi + ValueLo
End Function
Function CustomLo(BigValue as long) As Long
Shift Left BigValue, %bHi
Shift Right BigValue, %bHi
Function = BigValue
End Function
Function CustomHi(BigValue As Long) As Long
Shift Right BigValue, %bLo
Function = BigValue
End Function
'gbs_00999
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm