Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-16-2011, 07:41 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:46 AM.


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