Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Function DisplayAscii(tcChar)
Return asc(tcChar)
EndFunc
?DisplayAscii(substr(luBuffer, 1, 1))
?DisplayAscii(substr(luBuffer, 2, 1))
Function Buff2Num
LParameters tcBuffer, tnBytes
Local lnCurByte, lnRetVal as Integer
If (pcount() < 2)
If (len(tcBuffer) > 8)
Wait 'Max Buffer to pass is 8 character' window nowait
Return
else
tnBytes = len(tcBuffer)
endif
else
If (vartype(tnBytes) != 'N')
If (len(tcBuffer) > 8)
Wait 'Max Buffer to pass is 8 character' window nowait
Return
else
tnBytes = len(tcBuffer)
endif
endif
endif
lnRetVal = 0
For lnCurByte = 1 to tnBytes
lnRetVal = lnRetVal + ;
asc(substr(tcBuffer, lnCurByte, 1)) * ;
(256^(lnCurByte-1))
next
Return int(lnRetVal)
EndFunc
** convert "WORD" type
?Buff2Num(substr(lpBuffer,1,2))
** convert "DWORD" type
?Buff2Num(substr(lpBuffer,1,4))
** convert "QWORD" type
?Buff2Num(substr(lpBuffer,1,8))
?showhex("ÚG+2lD") && returns - "DA470F032B320F036C44"
?showascii("ÚG+2lD") && returns -
* 218, 71, 15, 3, 43, 50, 15, 3, 108, 68
* Program....: SHOWHEX.PRG
lparameters p_cBin
local lcString
lcString = ""
FOR lnii = 1 to len(p_cBin)
lnByte = asc(substr(p_cBin, lnii, 1))
lcHex = right(transform(lnByte,"@0x"),2)
lcString = lcString + lcHex
ENDFOR &&* lnii = 1 to len(p_cBin)
RETURN lcString
*!* EOP: SHOWHEX.PRG
* Program....: SHOWASCII.PRG
lparameters p_cBin
local lcString
lcString = ""
FOR lnii = 1 to len(p_cBin)
lcByte = str(asc(substr(p_cBin, lnii, 1)), 3)+", "
lcString = lcString + lcByte
ENDFOR &&* lnii = 1 to len(p_cBin)
RETURN left(lcString, len(lcString)-2)
*!* EOP: SHOWASCII.PRG
Procedure Num2DWord(tn_Num)
Local c0, c1, c2, c3
c3 = chr(int(tn_Num / 16777216))
tn_Num = mod(tn_Num, 16777216)
c2 = chr(int(tn_Num / 65536))
tn_Num = mod(tn_Num, 65536)
c1 = chr(int(tn_Num / 256))
c0 = chr(mod(tn_Num, 256))
Return c0 + c1 + c2 + c3
EndProc
* Program....: ASC2SBEINT.PRG
* Abstract...: Ascii String to Signed BigEndian Integer (i.e. Most significant byte on right)
* Handles 1 to 4 byte strings (could be easily be expanded)
*
* RETURN 0 if any error
*
* Example....: ? ASC2SBEINT(chr(255)+chr(255)+chr(255)+chr(255), 4, .T.)
* prints -1
*
* Changes....:
*FUNCTION asc2SBEint
LPARAMETERS p_cString, p_nLength, p_lSigned
IF PCOUNT() < 1 OR TYPE("p_cString") <> "C"
RETURN 0
ENDIF
IF PCOUNT() < 2 OR TYPE("p_nLength") <> "N"
p_nLength = LEN(p_cString)
ENDIF
IF PCOUNT() < 3 OR TYPE("p_lSigned") <> "L"
p_lSigned = .F.
ENDIF
IF p_nLength > LEN(p_cString)
p_cString = PADR(p_cString, p_nLength, CHR(00))
ENDIF
LOCAL lnRet_val
DO CASE
CASE p_nLength = 1
lnRet_val = int(asc(SUBSTR(p_cString, 1, 1)))
IF p_lSigned and lnRet_val >= 256/2
lnRet_val = -(256-lnRet_val)
ENDIF
CASE p_nLength = 2
lnRet_val = int(asc(SUBSTR(p_cString, 1, 1));
+ asc(SUBSTR(p_cString, 2, 1))*256)
IF p_lSigned and lnRet_val >= 256^2/2
lnRet_val = -(256^2-lnRet_val)
ENDIF
CASE p_nLength = 3
lnRet_val = int(asc(SUBSTR(p_cString, 1, 1));
+ asc(SUBSTR(p_cString, 2, 1))*256;
+ asc(SUBSTR(p_cString, 3, 1))*256^2)
IF p_lSigned and lnRet_val >= 256^3/2
lnRet_val = -(256^3-lnRet_val)
ENDIF
CASE p_nLength = 4
lnRet_val = int(asc(SUBSTR(p_cString, 1, 1));
+ asc(SUBSTR(p_cString, 2, 1))*256;
+ asc(SUBSTR(p_cString, 3, 1))*256^2;
+ asc(SUBSTR(p_cString, 4, 1))*256^3)
IF p_lSigned and lnRet_val >= 256^4/2
lnRet_val = -(256^4-lnRet_val)
ENDIF
OTHERWISE
lnRet_val = 0
ENDCASE
RETURN INT(lnRet_val)
*!* EOP: ASC2SBEINT.PRG