writing your own application layer protocol

Apr 10, 2019 at 9:26pm
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
Apr 10, 2019 at 9:38pm
Apr 11, 2019 at 8:25am
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.
Apr 11, 2019 at 1:56pm
thanks guys I don't know how I managed to post the same thing twice lol
Apr 11, 2019 at 2:17pm
If you notice this before people reply to both delete one of them...
Topic archived. No new replies allowed.