Hack Forums
[Java] [CHALLENGE] base B to base X - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] [CHALLENGE] base B to base X (/showthread.php?tid=3262022)



[CHALLENGE] base B to base X - +TOAST - Feb 15, 2013

Heres a java challenge for you folks bored at home.

Write a method to convert a number of any base to another number of any base.

example header:

Code
public static String toBaseX(String orig, int base, int outBase)

Heres an example message:

Code
System.out.println(toBaseX("24AF", 16, 10));

This should take the base 16 String 24AF, and convert it to a base 10 number.

Was just thinking about how to do this last night and I already have mine finished. Good luck :)


* - alphabot - Feb 15, 2013

Haven't done Java in a long time but this should work rofl.

Spoiler (Click to View)


* - +TOAST - Feb 15, 2013

(Feb 15, 2013 10:37 PM)alphabot Wrote:  Haven't done Java in a long time but this should work rofl.

Spoiler (Click to View)

I cried a little bit. I've been doing java for a long time and I haven't known about this feature...

Damn nice code golf there

edit
Then again, you cant specify your own charset. cant go from say, base 94 to base 95 your way :)


* - alphabot - Feb 15, 2013

(Feb 15, 2013 10:45 PM)tasty_mother Wrote:  I cried a little bit. I've been doing java for a long time and I haven't known about this feature...

Damn nice code golf there

edit
Then again, you cant specify your own charset. cant go from say, base 94 to base 95 your way :)

Base 94 isn't possible unless you use extended ascii anyway and nothing in any real world application will hardly ever go past base 10 let alone 16.


* - +TOAST - Feb 16, 2013

it is possible.

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`~!@ #$%^&*()_+-=[]\;',./{}|:"<>?

is 95 characters, so its completely possible


* - MrZander - Feb 16, 2013

(Feb 15, 2013 10:57 PM)alphabot Wrote:  Base 94 isn't possible unless you use extended ascii anyway and nothing in any real world application will hardly ever go past base 10 let alone 16.

Base 16 is incredibly common, virtually everyone uses it for color codes.
Also, Base 64 Encoding.