;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfHugeConvertToBase (strHugeNumBase10, intBaseTo) ; If any parameter contains invalid data, then return empty string. If strHugeNumBase10 == "" || intBaseTo > 36 || intBaseTo < 2 Then Return "" If StrClean (strHugeNumBase10, "0123456789", "", @TRUE, 1) != "" Then Return "" AddExtender ("WWHUG34i.DLL") ; The Huge Arithmetic Extender allows math on large numbers (up to 2000 digits). strNumTo = "" While strHugeNumBase10 != "0" strQuot = huge_Divide (strHugeNumBase10, intBaseTo) strHugeNumBase10 = ItemExtract (1, strQuot, ".") ; Huge number integer part. intMod = Int (huge_Multiply (huge_Subtract (strQuot, strHugeNumBase10), intBaseTo)) ; Huge number modulo part. strNumTo = StrSub ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1 + intMod, 1) : strNumTo EndWhile If strNumTo == "" Then strNumTo = "0" Return strNumTo ;.......................................................................................................................................... ; This UDF "udfHugeConvertToBase" converts a decimal number string of Base 10 to another number base in the range of Base 2 to Base 36. ; The given number string can be a WinBatch "huge integer number". ; ; Parameters: ; strHugeNumBase10 ... String of numbers (WinBatch "huge integer number"). ; intBaseTo ... Integer number, from 2 to 36, the new number base to convert the given decimal huge integer number into. ; ; Return value: ; strNumTo ... String of numbers and/or valid letters. Letters are in upper case. ; On parameter failure the return value is an empty string. ;.......................................................................................................................................... ; Algorithm adapted from ... ; Conf: WinBatch ; From: kdmoyers admin@guden.com ; Date: Thursday, December 27, 2001 12:50 PM ;.......................................................................................................................................... ; Modified by Detlev Dalitz.20020204.20100207.20100911(HugeNumber). ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfHugeConvertToBase_ (strHugeNumBase10, intBaseTo) ; If any parameter contains invalid data, then return empty string. If strHugeNumBase10 == "" || intBaseTo > 36 || intBaseTo < 2 Then Return "" If StrClean (strHugeNumBase10, "0123456789", "", @TRUE, 1) != "" Then Return "" arrDigits = ArrayFromStr (StrSub ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, intBaseTo)) AddExtender ("WWHUG34i.DLL") ; The Huge Arithmetic Extender allows math on large numbers (up to 2000 digits). strNumTo = "" While strHugeNumBase10 != "0" strQuot = huge_Divide (strHugeNumBase10, intBaseTo) strHugeNumBase10 = ItemExtract (1, strQuot, ".") ; Huge number integer part. intMod = Int (huge_Multiply (huge_Subtract (strQuot, strHugeNumBase10), intBaseTo)) ; Huge number modulo part. strNumTo = arrDigits [intMod] : strNumTo EndWhile If strNumTo == "" Then strNumTo = "0" Return strNumTo ;.......................................................................................................................................... ; This UDF "udfHugeConvertToBase" converts a decimal number string of Base 10 to another number base in the range of Base 2 to Base 36. ; The given number string can be a WinBatch "huge integer number". ; ; Parameters: ; strHugeNumBase10 ... String of numbers (WinBatch "huge integer number"). ; intBaseTo ... Integer number, from 2 to 36, the new number base to convert the given decimal huge integer number into. ; ; Return value: ; strNumTo ... String of numbers and/or valid letters. Letters are in upper case. ; On parameter failure the return value is an empty string. ;.......................................................................................................................................... ; Algorithm adapted from ... ; Conf: WinBatch ; From: kdmoyers admin@guden.com ; Date: Thursday, December 27, 2001 12:50 PM ;.......................................................................................................................................... ; Modified by Detlev Dalitz.20020204.20100207.20100911(HugeNumber). ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfHugeConvertFromBase (strNumFrom, intBaseFrom) ; If any parameter contains invalid data, then return empty string. If strNumFrom == "" || intBaseFrom > 36 || intBaseFrom < 2 Then Return "" strNumFrom = StrUpper (strNumFrom) If StrClean (strNumFrom, StrSub ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, intBaseFrom), "", @TRUE, 1) != "" Then Return "" AddExtender ("WWHUG34i.DLL") ; The Huge Arithmetic Extender allows math on large numbers (up to 2000 digits). strNumBase10 = "0" While strNumFrom != "" intPos = StrIndex ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", StrSub (strNumFrom, 1, 1), 1, 0) strNumBase10 = huge_Add (huge_Multiply (strNumBase10, intBaseFrom), intPos - 1) strNumFrom = StrSub (strNumFrom, 2, -1) EndWhile Return strNumBase10 ;.......................................................................................................................................... ; This UDF "udfHugeConvertFromBase" converts a number string of a number base in the range of Base 2 to Base 36 ; into a decimal number string of Base 10. ; ; Parameters: ; strNumFrom ... String of numbers and/or valid letters. Letters can be in upper or lower case. ; intBaseFrom ... Integer number (2..36), the number base of the given number string. ; ; Return value: ; strNumBase10 ... String of numbers of number base 10, a so called "huge integer number". ; On parameter failure the return value is an empty string. ;.......................................................................................................................................... ; Algorithm adapted from ... ; Conf: WinBatch ; From: kdmoyers admin@guden.com ; Date: Thursday, December 27, 2001 12:50 PM ;.......................................................................................................................................... ; Modified by Detlev Dalitz.20020204.20100207.20100911(HugeNumber). ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. strNumBase10 = "12345678901234" strListTemp = "" :Test1 strMsgToBase = "Convert decimal number " : strNumBase10 : " from Base 10 to Base B (2..36) number:" : @LF For intBaseTo = 2 To 36 strToBase = udfHugeConvertToBase (strNumBase10, intBaseTo) strListTemp = ItemInsert (strToBase, -1, strListTemp, @TAB) strMsgToBase = strMsgToBase : @LF : "Base" : @TAB : intBaseTo : @TAB : strToBase Next strMsgTitle = "Demo|udfHugeConvertToBase (strNumBase10, intBaseTo)" Pause (strMsgTitle, strMsgToBase) :Test2 strMsgFromBase = "Convert number from Base B (2..36) to Base 10 decimal number:" : @LF For intBaseFrom = 2 To 36 strNumFrom = ItemExtract (intBaseFrom - 1, strListTemp, @TAB) strMsgFromBase = strMsgFromBase : @LF : strNumFrom : @TAB : @TAB : "Base" : @TAB : intBaseFrom : @TAB : udfHugeConvertFromBase (strNumFrom, intBaseFrom) Next strMsgTitle = "Demo|udfHugeConvertFromBase (strNumFrom, intBaseFrom)" Pause (strMsgTitle, strMsgFromBase) :Test3 ; Number conversion. ; From: "1IAHEB54638829348494387383AD12" (Base 19) ; To: "136615251021020315364261540624105412221316016" (Base 7). strNumB19 = "1IAHEB54638829348494387383AD12" strNumB7 = udfHugeConvertToBase (udfHugeConvertFromBase (strNumB19, 19), 7) strMsgTitle = "Demo|Convert number from Base 19 to Base 7." strMsgText = "Number (Base19): " : @LF : strNumB19 strMsgText = strMsgText : @LF : "Number (Base7): " : @LF : strNumB7 Pause (strMsgTitle, strMsgText) :Test4 strResult1 = udfHugeConvertFromBase ("123", 10) ; "123" (B10) ; OK. strResult2 = udfHugeConvertFromBase ("12A", 10) ; "" ; Error: Digit "A" not allowed in Base 10. strResult3 = udfHugeConvertFromBase ("12A", 11) ; "153" (B11) ; Digit "A" allowed in Base 11. :CANCEL Exit