• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Unit Id to integers

Status
Not open for further replies.
Is there a website somewhere I can use that can convert a four letter code into numbers? What I mean by this is something like a unit id such as 'ffsc' becomes 1717990243. I know how to do it in-game, I was just wondering if there wasn't a way to do it without constantly having to go in-game and issuing the order to retrieve the numerical equivalent.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
As TriggerHappy said, it is simple ascii code with super-high base numbers.

In the "regular" counting system, we count in base 10.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Everytime we add 1 to the last number, we increase the number before that by 1 and switch that last number to 0.
19 +1 = 20, 29 +1 = 30, etc

You can also count in lower base systems, like base2 (binary):
0, 1
001 is 1
010 is 2
011 is 3
100 is 4
etc.

The 4 character code is exactly the same, except it is in base256.
In any base higher than 10, you need additional characters because you cant do:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. for obvious reasons... what is 112?
1-1-2 or 1-12?
So you need additional characters for example:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f. (hex codes)
In base256 there is one difference, that you dont start with 0, instead you just use the ascii numbers (or rather, you show a character that belongs to the ascii value).
You can find Ascii Tables all over the internet and there are a few different versions of them and with different number of characters.
Finding the values in those tables may not be funny to do and there are some converters on the internet like this one.
You type in "a" and it shows "97" which is the ascii number of "a".
However, if you type another "a" it shows "9797" which is not how base256 works.
The converter simply puts "97" and "97" next to each other.
Base256 should multiply that first 97 by 256 (the base) to the power of the position of the character counting from the right... in this case 1... which is 256^1 which is 256.
And it should add the two values together, so:
(97 * 256^1) + (97 * 256^0) =
(97 * 256) + (97 * 1) =
24832 + 97 =
24929

With 4 characters "abcd" would be:
('a' * 256^3) + ('b' * 256^2) + ('c' * 256^1) + ('d' * 256^0) = 'abcd'
I am not a big fan of online converters so I dont really know any, and I couldn't find one out of the blue.
On the other hand, I always have Netbeans opened, which is an IDE that supports a ton of programming languages.
If I need such a converter, I write one:
Code:
    public static int Ascii2Integer(String ascii)
    {
        byte[] arr = { 0x00, 0x00, 0x00, 0x00, };
        for (int i = 0; i < 4 && i < ascii.length(); i++)
        {
            arr[i] = (byte)ascii.charAt(i);
        }
        return ByteBuffer.wrap(arr).getInt();
    }
    
    public static String Integer2Ascii(int num)
    {
        ByteBuffer b = ByteBuffer.allocate(4);
        b.putInt(num);
        return new String(b.array());
    }
    
    public static void main(String[] args)
    {
        System.out.println(Ascii2Integer("abcd"));
        System.out.println(Integer2Ascii(1633837924));
        System.out.println(Integer2Ascii(Ascii2Integer("abcd")));
    }

Base1 is also funny but hard to explain.

EDIT:
In addition to DracoL1ch's post:
You only need the Character field and the Decimal field.
The others are in different bases.

EDIT:
The reason for using 4 characters is because a character is made out of one byte (aka 8 bits, 256 different states), an integer is 4 bytes (aka 32 bits, 4294967296 different states).
So 4 characters (aka 4 bytes) is one integer.
 
Last edited:
Status
Not open for further replies.
Top