cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
user name:
password:
Forgot your password?
please wait
try again
cancel
forgot your password?
sign up
log in
[Legacy version]
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
writing your own application layer proto
writing your own application layer protocol
Apr 10, 2019 at 9:26pm
Apr 10, 2019 at 9:26pm UTC
adam2016
(1529)
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 10, 2019 at 9:38pm UTC
helios
(17607)
What are you doing?
http://www.cplusplus.com/forum/general/252152/
Apr 11, 2019 at 8:25am
Apr 11, 2019 at 8:25am UTC
coder777
(8449)
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
Apr 11, 2019 at 1:56pm UTC
adam2016
(1529)
thanks guys I don't know how I managed to post the same thing twice lol
Apr 11, 2019 at 2:17pm
Apr 11, 2019 at 2:17pm UTC
jonnin
(11494)
If you notice this before people reply to both delete one of them...
Topic archived. No new replies allowed.