writing your own application layer protocol

Hi guys,

I am following this blog on how to write your own protocol - https://mayaposch.wordpress.com/2011/10/03/design-your-own-protocol-in-five-minutes/

personally I don't think she explains enough and doesn't actually show the finished product I'm sure there is more code than that

but anyway
1
2
3
for (int i = sizeof(size); i > 0 ; --i) {
data.append((size >> (i * 8)) & 0xFF);
}


my question is what is happening here with the bitwise operators

what is she appending to the end of the array?

why is she right shifting the result of i * 8 and then bitwise anding it with 0xFF?

thanks
what is she appending to the end of the array?
A single byte taken from size

why is she right shifting the result of i * 8 and then bitwise anding it with 0xFF?
It stores the variable size with the least significant byte first.

'anding it with 0xFF' is masking out one byte.
thanks guys I don't know how I managed to post the same thing twice lol
If you notice this before people reply to both delete one of them...
Topic archived. No new replies allowed.