Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Working at the Bit Level
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP
Network:
Novell 6.x
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01365539
Message ID:
01365668
Vues:
15
FUNCTION Int2Bin(num As Number) As String
	DO CASE
	CASE m.num = 0
		RETURN "0"
	CASE m.num < 0
		num = 0x100000000 + m.num
	ENDCASE
	LOCAL cResult, nIndex
	cResult = ""
	FOR nIndex=MIN(31, CEILING(LOG(m.num)/LOG(2))) TO 0 STEP -1
		cResult = m.cResult + IIF(BITTEST(m.num, m.nIndex), "1", "0")
	NEXT
RETURN cResult

FUNCTION Bin2Int(cBinStr As String) As Number
	LOCAL nIndex, ch, nResult, nPower
	STORE 0 TO nResult, nPower
	
	FOR nIndex=LEN(cBinStr) TO 1 STEP -1
		ch = SUBSTR(m.cBinStr, m.nIndex, 1)

		DO CASE
		CASE m.ch = '1'
			nResult = m.nResult + 2 ^ m.nPower
		CASE m.ch = '0'
		OTHERWISE
			LOOP
		ENDCASE
		nPower = m.nPower + 1
	NEXT
RETURN INT(m.nResult)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform