Wolvereness Posted January 19, 2005 Share Posted January 19, 2005 (edited) I am proud to announce the first of 2-3 different converters that will convert numbers to/from any base system! This one will convert a decimal number into any base system you would like. Note, when a character goes > Z it will place strange characters on the system. This function also converts numbers into binary! Further note, this function returns a STRING as so it wont be considered a floating number for base ten. Usage: _DecConvert(Number to convert, Place values to have, Base system to use) Return value: Number with place values (ones not used = 0) and proper base system. Return value failure: 0 and @error = 1 Func _DecConvert($i_Number, $i_PlaceValue, $i_Base) If Abs(Int($i_Number)) = $i_Number And Abs(Int($i_PlaceValue)) = $i_PlaceValue And Abs(Int($i_Base)) = $i_Base And $i_Number And $i_PlaceValue And $i_Base Then Local $i_Count, $s_Values = '', $i_Temporary For $i_Count = 1 To $i_PlaceValue $i_Temporary = Int($i_Number / $i_Base ^ ($i_Count - 1) ) If $i_Temporary Then $i_Temporary = Mod($i_Temporary, $i_Base) If $i_Temporary <> $i_Base Then If $i_Temporary > 9 Then $i_Temporary = Chr(55 + $i_Temporary) $s_Values = $i_Temporary & $s_Values ContinueLoop EndIf EndIf $s_Values = '0' & $s_Values Next SetError(0) Return $s_Values Else SetError(1) Return 0 EndIf EndFunc Edited January 19, 2005 by Wolvereness Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote] Link to comment Share on other sites More sharing options...
ezzetabi Posted January 19, 2005 Share Posted January 19, 2005 It remembers me something... Link to comment Share on other sites More sharing options...
Wolvereness Posted January 20, 2005 Author Share Posted January 20, 2005 Damn, I never came across that. I was working at school and I needed a Dec to Bin converter... Oh well, I guess I'll just try to make the BaseToBase() converter... Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote] Link to comment Share on other sites More sharing options...
ezzetabi Posted January 20, 2005 Share Posted January 20, 2005 I prefere keeping the two function separed since you can't actually convert from any base to an other any base, you always pass to the base 10. Link to comment Share on other sites More sharing options...
Wolvereness Posted January 20, 2005 Author Share Posted January 20, 2005 I mean was something like converting bin to hex. Something like:_BaseToBase($i_Number, $i_OriginalBase, $i_NewBase) Well, where you do not I will try. I'm still sad because my func had already been done... Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote] Link to comment Share on other sites More sharing options...
ezzetabi Posted January 20, 2005 Share Posted January 20, 2005 Did you read what I said? You can easily integrate the two functions, nothing to brag about, but they'll actually pass to the base ten. E.g. Base 2 to base 16 10011111, you have to calculate it in base 10 that means 159 raising to power all digits and after converting it to hex that means 9F with modulus operations. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now