Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Base-10 Converter (https://forums.graalonline.com/forums/showthread.php?t=134261707)

Tigairius 01-16-2011 07:41 PM

Base-10 Converter
 
Here's something I needed. It's probably useless to most people. Convert positive base10 integers.

PHP Code:

function ConvertBase(targetbase) {
  if (
base == || base == 0) return 0;
  
temp.basestring "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  
  while (
target 0) {
    
temp.newstring @= temp.basestring.charat(target base);
    
target int(target/base);
  }
  
  for (
temp.temp.newstring.length(); temp.>= 0temp.--) temp.output @= temp.newstring.substring(temp.i1);
  
  return 
temp.output;


Example of usage:
ConvertBase(5544, 2) converts the number 5544 to binary, 1010110101000.
ConvertBase(5544, 16) converts the number 5544 to base 16, 15A8.
ConvertBase(5544, 36) converts the number 5544 to base 36, 4A0.

Have fun.

Soala 01-16-2011 08:37 PM

Nice, but I fail to see what it would be used for. I'd rather convert things myself, but if it's a real big number then maybe :)

Codein 01-16-2011 09:28 PM

Hahaha, that's cool. As you said, mostly useless, but still cool. Wouldn't be so bad when inspecting bitmasks, if anything.

Fulg0reSama 01-16-2011 09:51 PM

Hey making useless stuff is my thing >:(

Whatever, nice job Tig.


All times are GMT +2. The time now is 09:51 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.