How to convert Int to uint8?

how to convert Int to uint8?

I try to do this:

int test_data = 123456;

uint8* send_data;

send_data = (uint8*)test_data;

But send_data does not seem to be 123456

1 Like

send_data = (uint8*) &test_data;

Note the & symbol. It means “address of”. Pointers need the address of the variable. You were assigning the value of the int to the pointer. Then when you want the value being pointed to by a pointer, you use the * symbol:

int newInt = *(int*) test_data;

Also keep in mind that int and uint8 are not the same size so you will need to send “sizeof(int)” bytes of data.

Thank you, I’m trying

This is the code I’m testing:

int test_data = 123456;
uint8* send_data = (uint8*)&test_data;
int32 sent = 0;
Socket->Send(send_data, sizeof(int), sent);

It works, thanks :slight_smile: