mIRC Home    About    Download    Register    News    Help

Print Thread
$base function #128907 31/08/05 04:01 AM
Joined: Aug 2005
Posts: 18
M
Mail Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Aug 2005
Posts: 18
I am needing a better understanding of the $base function other than what the mIRC help file contains. More details than what is in that file would be great. I have a slight understanding of it but the code I am working on needs to utilize it more than once and I dont want to keep asking one person for these details. Any information available to be read online that contains these details would be greatly appreciated.

Moved to Scripts & Popups

Last edited by Mentality; 31/08/05 09:17 AM.
Re: $base function #128908 31/08/05 11:39 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
$base(N,inbase,outbase,zeropad,precision)
Converts number N from inbase to outbase. The last two parameters are optional.

A numbers BASE essentially means how many didgits there are before you add one to the next column, so base 10 has 0,1,2,3,4,5,6,7,8,9 (ie :10 numebers)
Hex has 16 (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) letters used as there arent 16 nunmeric symbols
octal has 8 (0,1,2,3,4,5,6,7)

So lets say you have the number 255 decimal that is FF hex and ummm 377octal

//echo -a $base(255,10,16)
FF
//echo -a $base(255,10,8)
377
//echo -a $base(FF,16,8)
377
//echo -a $base(FF,16,10)
255
//echo -a $base(377,8,16)
FF
//echo -a $base(377,8,10)
255

$base just converts from one BASE to another, you give it the number and the base that number is in and the base you want that number to come out in.

Just to be sure u understand what a base is, this is base 3 (0,1,2) (i well zero pad the ledding spaces
//var %i = 0 | while (%i <= 9) { echo -a %i = $base(%i,10,3,4) | inc %i }
0 = 0000
1 = 0001
2 = 0002
3 = 0010
4 = 0011
5 = 0012
6 = 0020
7 = 0021
8 = 0022
9 = 0100

the base 3 value of 0022 or 22 is not Twentytwo but 22 (base3) which is eight.

Binary is of course base 2 (0,1)

The other two fields to the $BASE are just leading zero pads (as used in the base 3 example), and number of decimal places u want to show/use