Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert hex to CRC
Message
 
À
19/07/2002 06:12:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00680343
Message ID:
00680420
Vues:
17
It was MS Q192303, but I cannot find it anymore. So, here is what I am using, based on that article.


*MS Q192303
*-- Code begins here.
WAIT WINDOW "-" + STR(2146828218) + " = " + DecToHex(-2146828218)
WAIT WINDOW STR(-43690) + " = " + DecToHex(-43690)
WAIT WINDOW STR(43690) + " = " + DecToHex(43690)

*-----------------------------------------------------------------
*- Function: DecToHex
*- Summary: Converts decimal integers to hex strings, whether
*- signed or unsigned.
*- Parameters: liDecNumber - decimal number to convert.
*-----------------------------------------------------------------
FUNCTION DecToHex
PARAMETERS liDecNumber
lsHexNumber = ""
IF liDecNumber > 0 && It's not negative, so do a straight TRANSFORM.
lsHexNumber = TRANSFORM(liDecNumber, "@0")
ELSE

*-- The number is negative, so we'll have to do a little more work,
*-- since it's not as straight forward as converting and adding a
*-- minus sign.

*-- Find the length of the resulting hex string.
lsHexNumber = TRANSFORM(ABS(liDecNumber), "@0")
IF SUBSTR(lsHexNumber, 3, 1) = "0" && The number has filled the
&& eight places of DWORD.
liLength = LEN(SUBSTR(lsHexNumber, NotAt("0", lsHexNumber, 2)))
ELSE
*-- Subtract to account for "0x".
liLength = LEN(TRANSFORM(ABS(liDecNumber), "@0")) - 2
ENDIF

lsTempHex = 0xFFFFFFFF
lsHexNumber = TRANSFORM(lsTempHex-ABS(liDecNumber) + 1, "@0")
ENDIF
RETURN lsHexNumber

*-----------------------------------------------------------------
*- Function: NotAt
*- Summary: From within a passed string, finds the first
*- occurrence of a character that is not the character
*- specified. In other words, this function works
*- opposite of the manner that AT() does.
*- Parameters: lsNotString - What we don't want. The function
*- finds the first character that is
*- not lsNotString.
*- lsSearchString - The string in which to search.
*- liOccurence - Indicates that NotAt should find
*- the liOccurence of a character
*- that is not lsNotString.
*-----------------------------------------------------------------
FUNCTION NotAt()
PARAMETERS lsNotString, lsSearchString, liOccurrence

llFound = .F. && Flag indicates if we've found a character that
&& is NOT lsNotString
llEndOfString = .F. && Flag to indicate that we've reached the end
&& of the string.
lnCounter = 0 && Tracks position during the search.
lnLength = LEN(lsSearchString)
liOccurCount = 0 && Tracks how many occurrences have been found.

*-- Loop until the desired character is found or the end of
*-- the string is reached.
DO WHILE NOT llFound AND NOT llEndofString
lnCounter = lnCounter + 1
lsCompare = SUBSTR(lsSearchString, lnCounter, 1)
IF lsCompare <> lsNotString
liOccurCount = liOccurCount + 1

*-- Have we found the occurrence we want?
IF liOccurCount = liOccurrence
llFound = .T.
ENDIF
ENDIF
IF lnCounter = lnLength
llEndOfString = .T.
ENDIF

ENDDO
RETURN lnCounter
*-- Code ends here.

>Has anybody made or seen a routine that converts a hex string to a float.
>The hex-string has the following struct:
>
>Byte3 Byte4 Byte1 Byte2
>MMMMMMMM MMMMMMMM SEEEEEEE EMMMMMMM
>
>M:Mantisse
>E:Exponent
>S:Sign
>
>(example: 550.0 ->0x44098000)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform