Icon

Furcadia Technical Resources

Back | Conversion Functions | Digit Table | Home Area | Data Dump | Furcadia
Icon2

base95 Numbering System

You might have already noticed that Furcadia doesn't use a decimal numbering system to specify coordinates and just about anything else. In order to reduce bandwidth usage in favor of those who don't own a fast connection to the server, the system uses base95 numbers instead of base10.
Why? Because in one byte of the base10 (decimal) system you can only have 10 numbers (0 - 9), while in the base95 system you can get up as high as 95 numbers (0 - 94 [sp - ~]). In case of two bytes, we are talking about 100 numbers (00 - 99) versus 9025 numbers (00 - 9024 [spsp - ~~]).
If you still find it a bit complex, no matter. You will probably understand the concept later on.

Conversion Between Bases

Obviously, since we all are used to good old decimal numbers of the base10 system, we will most definitely want to convert these scary leters into something we understand more. Here is a little equation you have to do in order to convert a base95 number into a decimal one (assuming that the number is valid and that the number consists of 2 bytes!):

n = ((byte[0] - 32) * 95) + (byte[1] - 32)

Note that we are dealing with unsigned numbers - there should be no negative values in Furcadia's data!

From this point you can probably go as far as 3-byte numbers and further, but in our case it's not really necessary, since probably the maximal number you will see in Furcadia won't go over two bytes. Here is a pair of equations that would convert a decimal number between 0 and 9024 into a base95 number:

byte[0] = (n / 95) + 32
byte[1] = (n % 95) + 32

The numbers in byte[0] and byte[1] are leters in the second area of the ASCII table (32 - 127). We use that particular area because it's the most "sane" one in the entire table and you won't face any troubles typing these numbers on your keyboard...

Well, that's about it. Now you know how to get sane numbers out of what you can see, passing through to your Furcadia client. This is the main part of understanding the protocol because most of it consists of these very numbers. After this point, the protocol shouldn't be looking as strange as it used to in the very beginning.

C/C++ Conversion Functions

/*** String to Integer ***/
short StoI (const char * byte)
{
    if (((unsigned char) byte[0] < 32) || ((unsigned char) byte[0] > 126)) return -1;
    if (((unsigned char) byte[1] < 32) || ((unsigned char) byte[1] > 126)) return -1;
    return (((unsigned char) byte[0] - 32) * 95) + ((unsigned char) byte[1] - 32));
}

/*** Integer to String ***/
void ItoS (char * byte, short n)
{
    if (n < 0) n = 0;
    if (n > 9024) n = 9024 ;

    byte[0] = (unsigned char)((n / 95) + 32);
    byte[1] = (unsigned char)((n % 95) + 32);
    byte[2] = '\0';
}

Digit Table

If you can't be bothered doing it on your own, here is a table of digits for the base95 system, it's decimal value nearby.
In case and you didn't know, we use leters and other characters for numbers because humans never invented a digit higher than 9 - they haven't had the need to. That's why in hexadecimal (base16) systems you see it going from 9 to A and then after F the number becomes two digits long...

[DEC] [base95]
0 space
1 !
2 "
3 #
4 $
5 %
6 &
7 '
8 (
9 )
10 *
11 +
[DEC] [base95]
12 ,
13 -
14 .
15 /
16 0
17 1
18 2
19 3
20 4
21 5
22 6
23 7
[DEC] [base95]
24 8
25 9
26 :
27 ;
28 <
29 =
30 >
31 ?
32 @
33 A
34 B
35 C
[DEC] [base95]
36 D
37 E
38 F
39 G
40 H
41 I
42 J
43 K
44 L
45 M
46 N
47 O
[DEC] [base95]
48 P
49 Q
50 R
51 S
52 T
53 U
54 V
55 W
56 X
57 Y
58 Z
59 [
[DEC] [base95]
60 \
61 ]
62 ^
63 _
64 `
65 a
66 b
67 c
68 d
69 e
70 f
71 g
[DEC] [base95]
72 h
73 i
74 j
75 k
76 l
77 m
78 n
79 o
80 p
81 q
82 r
83 s
[DEC] [base95]
84 t
85 u
86 v
87 w
88 x
89 y
90 z
91 {
92 |
93 }
94 ~

Copyright © 2004-2005 by IceDragon - All rights reserved