Answer» In my chess game, I'm trying to store a list of moves whereby one hexidecimal contains two coordinates. The board is SPLIT into squares, each square given an ID number. 0, 1, 2... 63.... I want the number to store the starting square and ending square like this.
0x1720 means a move from 17 (dec 23) to 20 (dec 32). Using 0x1720 & 0xFF00 I can get 0x1700 and 0x1720 & 0x00FF I can get 0x20. How can I get the 17 part from 0x1700?
What happens if the coordinates are below 10? Then I'd get say 0x32 (for 3 and 2) which obviously won't work with the above opperations. Would the best thing to do be to add 0x10 to each coordinate first, then subtract 0x10 at the end?
I don't have much experiance with hexidecimals. Any advice appreciated. Use the bitwise operators of your favoured progamming language? i.e. shift the number however MANY bits to the right that you require. (If you can't work it out, use TRIAL and error. )What programming language are you using? In C++ (or any other I imagine) you could make an array of values.
int CHESS_BOARD[8][8]; CHESS_BOARD[xvalue][yvalue]=whatever; //<----[set up in a grid]
or
int PSUDO_BOARD[64]; PSUDO_BOARD[8*yvalue+xvalue]=whatever; //<----[set up in a line]
these would be much easier to reference(even w/ hex).Thanks but the point was I wanted to be able to store a starting coordinate and an ending coordinate in a single variable. I gave up and now I simply use two variables for the TASK. I figured the amount of time I was spending getting it to work wasn't worth the time I'd save with that method It'd make more sense with an OO object... Feel free to explain what to do I figured out a way to EXTRACT 2 values from a single variable.(in case you're interested)
/*You need 3 values to encrypt your variable 1.) var 1 (VAR_1) 2.) var 2 (VAR_2) 3.) prime number (PRIME_NUMBER)*/ ENCRYPTED_VAR = PRIME_NUMBER*VAR_1+VAR_2;
/*You need 2 values to decrypt your variable 1.) prime number (PRIME_NUMBER) 2.) your encrypted variable (ENCRYPTED_VAR)*/ VAR_2 = ENCRYPTED_VAR%PRIME_NUMBER; VAR_1 = (ENCRYPTED_VAR-VAR_2)/PRIME_NUMBER;
This works better if the Prime Number is larger than the variables. Works sort of like "public key encryption".
|