Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: my Hex

  1. #1
    Member wolfgar's Avatar
    Join Date
    Oct 2009
    Location
    the middle of the woods
    Posts
    89
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default [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

    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;
    	}
    Last edited by wolfgar; January 26th, 2010 at 12:30 PM.
    Programming: the art that fights back


  2. #2
    Member wolfgar's Avatar
    Join Date
    Oct 2009
    Location
    the middle of the woods
    Posts
    89
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default 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
    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;
    	}
    Programming: the art that fights back

  3. #3
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: my Hex

    Just a note would it not be easier using this sort of stuff.

    		int x = 10;
     
    		System.out.println(x);
     
    		x = 0x000f;
     
     
    		System.out.println(x);
     
    		System.out.println(Integer.toHexString(x));

  4. #4
    Member wolfgar's Avatar
    Join Date
    Oct 2009
    Location
    the middle of the woods
    Posts
    89
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default 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
    Programming: the art that fights back

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.

    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));

  6. #6
    Member wolfgar's Avatar
    Join Date
    Oct 2009
    Location
    the middle of the woods
    Posts
    89
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: my Hex

    ok , though it doesn't really answer the question it gave me an idea of an easy work around , ty
    Programming: the art that fights back