hi
I've been reading some tutorials on packing a message before sending it to the server..and I haven't been doing very well..
I have here an example of a message being packed can someone explain the few lines that use hexadecimals?
Code:
unsigned char buffer [100];
int id, i=0, type;
char data [1024];
printf ("\nEnter an id number:");
scanf("%d", &id);
printf ("\nEnter a type between <3 :");
scanf("%d", &type);
printf ("\nEnter a message of 50 characters at max:");
scanf("%s", data);
int length = strlen(message);
//pack the id number
buffer[i++] = (unsigned char)((id & 0xff000000) >> 24);
buffer[i++] = (unsigned char)((id & 0xff0000) >> 16);
buffer[i++] = (unsigned char)((id & 0xff00) >> 8);
buffer[i++] = (unsigned char)(id & 0xff);
//pack the type
buffer[i] = (unsigned char)(type & 0x03);
buffer[i] = buffer[i]<<6;
//pack the length
buffer[i] = buffer[i] | (length & 0x0000003F);
i++;
//pack the data
memcpy(&buffer[i], &data[0], length);
i = i+length;
thanks