Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[HELP] Convert BYTE

Newbie Spellweaver
Joined
Mar 13, 2008
Messages
38
Reaction score
2
Hi, how are you? i need help to convert a data type BYTE to binary and modify binary; or modify BYTE

for example I have:

BYTE convert=0x40

I want change the 4(four to A) and the 0(zero to 8)

So when finish I must have: converted: 0xA8

My idea:
Convert(40 Hex, 64 decimal, to binary: 01000000
take the first 4 bits(0100) and change for: 1010
take the last 4 bits(0000) and change for: 1000
So the modified byte is: 10101000 converted to hex: A8

Do you have some idea?
 
Last edited:
Junior Spellweaver
Joined
Oct 27, 2008
Messages
165
Reaction score
89
So what you want to get the high and low 4 bytes from a byte, and set other values, kinda does not have any sense, you can use bit-wise operators;
PHP:
unsigned char byte = 0x40;
unsigned char low = 0x08
unsigned char high= 0x0A;
byte = ((high << 4)&0xF0) |( low &0x0F)

Or you could simply use:
PHP:
unsigned char byte= 0xA8;
 
Last edited:
Newbie Spellweaver
Joined
Mar 13, 2008
Messages
38
Reaction score
2
I really need convert:

Natural HEX | Converted Hex
0 | 8
1 | 9
2 | 6
3 | 7
4 | A
5 | B
6 | 2
7 | 3
8 | 0
9 | 1
A | 4
B | 5
C | F
D | E
E | D
F | C
And as you know a byte must can contain 2 Hex and I need convert both byte on the "crypted/decrypted" byte

More examples:

E6 to D2
C8 to F0
 
Last edited:
Junior Spellweaver
Joined
Oct 27, 2008
Messages
165
Reaction score
89
You could create a shifting table, if you are sure this is the corrects results:
PHP:
unsigned char shiftingTable[] = { 8, 9, 6, 7, A, B, 2, 3, 0, 1, 4, 5, F, E, D, C };
unsigned char low = convert &0x0F;
unsigned char high  = convert &0xF0 >> 4;
convert = ((shiftingTable[high] << 4 )& 0xF0) |( shiftingTable[low] & 0x0F);
 
Last edited:
Back
Top