# my Hex

Printable View

• January 26th, 2010, 03:38 AM
wolfgar
[self solved] my Hex
if u've ever used a game shark chances are u've also used it on a game that has so many codes and code combos that you get lost in the list,and if not u should try making a custom unit in ogre battle 64 @_@ lol
but that aside the game shark uses hexadecimal based codes , so i'm trying to make a program that will make finding a certain code combo a lot easier ( for the above mentioned game ) .
as i was looking at the codes i realized their all organized very well , so well all i need to do is put in the character codes for player 1 , and then add n to the pre-existing hex address to get the code for that character slot. sounds easy , except for the fact that i cant find a hexadecimal class that can add and subtract integers from the hex code .
so now that u know exactly what i need and why , here's the code and my problem ...

i put in "0000000f"
that should give me the number 15 when i call this method
instead i get 150000000
help plz

strHex is the input for this

Code :

```public int toInt(){ char[] list = strHex.toCharArray(); int[] places = new int[8]; int total = 0; for (int i = 0; i < 8;i++){ System.out.println("1st "+i); System.out.println(list[i]); System.out.println(15 * (Math.pow(10, i))); switch (list[i]){ case '0': places[i] = (int) (0 * Math.pow(10, i)); break; case '1': places[i] = (int) (1 * Math.pow(10, i)); break; case '2': places[i] = (int) (2 * Math.pow(10, i)); break; case '3': places[i] = (int) (3 * Math.pow(10, i)); break; case '4': places[i] = (int) (4 * Math.pow(10, i)); break; case '5': places[i] = (int) (5 * Math.pow(10, i)); break; case '6': places[i] = (int) (6 * Math.pow(10, i)); break; case '7': places[i] = (int) (7 * Math.pow(10, i)); break; case '8': places[i] = (int) (8 * Math.pow(10, i)); break; case '9': places[i] = (int) (9 * Math.pow(10, i)); break; case 'a': places[i] = (int) (10 * Math.pow(10, i)); break; case 'b': places[i] = (int) (11 * Math.pow(10, i)); break; case 'c': places[i] = (int) (12 * Math.pow(10, i)); break; case 'd': places[i] = (int) (13 * Math.pow(10, i)); break; case 'e': places[i] = (int) (14 * Math.pow(10, i)); break; case 'f': places[i] = (int) (15 * Math.pow(10, i)); break; } } for (int a = 7; a > -1;a--){ System.out.println(total); System.out.println(places[a]); total += places[a]; System.out.println("2nd "+a);   } System.out.println(total); return total; }```
• January 26th, 2010, 11:22 AM
wolfgar
Re: my Hex
.... i should have really waited to post here ><
cause after trying 2 more things it worked XD

i realized that the reason it was failing is the loop
was taking what ever int it had and also useing that
as the decimal place . so i added a "loop place inverter"
to it and it worked

the working code for any 1 that wants it
Code :

```public int toInt() { char[] list = strHex.toCharArray(); int[] places = new int[8]; int total = 0; for (int i = 1; i < 9; i++) { int a = 8 + (i - (i * 2)); System.out.println("reversed = "+a); switch (list[a]) { case '0': places[a] = (int) (0 * Math.pow(16, i-1)); break; case '1': places[a] = (int) (1 * Math.pow(16, i-1)); break; case '2': places[a] = (int) (2 * Math.pow(16, i-1)); break; case '3': places[a] = (int) (3 * Math.pow(16, i-1)); break; case '4': places[a] = (int) (4 * Math.pow(16, i-1)); break; case '5': places[a] = (int) (5 * Math.pow(16, i-1)); break; case '6': places[a] = (int) (6 * Math.pow(16, i-1)); break; case '7': places[a] = (int) (7 * Math.pow(16, i-1)); break; case '8': places[a] = (int) (8 * Math.pow(16, i-1)); break; case '9': places[a] = (int) (9 * Math.pow(16, i-1)); break; case 'a': places[a] = (int) (10 * Math.pow(16, i-1)); break; case 'b': places[a] = (int) (11 * Math.pow(16, i-1)); break; case 'c': places[a] = (int) (12 * Math.pow(16, i-1)); break; case 'd': places[a] = (int) (13 * Math.pow(16, i-1)); break; case 'e': places[a] = (int) (14 * Math.pow(16, i-1)); break; case 'f': places[a] = (int) (15 * Math.pow(16, i-1)); break; } } for (int a = 7; a > -1; a--) { total += places[a];     } System.out.println("return = "+total); return total; }```
• January 26th, 2010, 11:33 AM
Freaky Chris
Re: my Hex
Just a note would it not be easier using this sort of stuff.

Code :

``` int x = 10;   System.out.println(x);   x = 0x000f;     System.out.println(x);   System.out.println(Integer.toHexString(x));```
• January 26th, 2010, 01:05 PM
wolfgar
Re: my Hex
>< i had no idea something like that existed
u know if theirs a similar thing that could convert
from hex to int with that can hold at least
0xFFFFFFFF = 4294967295
• January 26th, 2010, 03:28 PM
helloworld922
Re: my Hex
Regardless of how you choose to enter that value (hex, binary, decimal, or even octal) it will have the same value. It's all in how you want that value displayed. By default, Java will display a number in it's decimal form.

Code :

```int x = 16; System.out.println(x); System.out.println(Integer.toHexString(x)); x = 0x10; // this is also 16 System.out.println(x); System.out.println(Integer.toHexString(x));```
• January 27th, 2010, 04:31 PM
wolfgar
Re: my Hex
ok , though it doesn't really answer the question it gave me an idea of an easy work around , ty