Archived

This topic is now archived and is closed to further replies.

Slice a byte.

This topic is 5184 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What language are you using?
I assume c or c++.

to "delete" some bits from a byte, you have to mask them out.
and you can''t really "delete" them, they''re still there, I assume you just want to set them to 0.

You have 8 bits in a byte (as stated)
what you want to do is AND two bytes together.

source_byte = source_byte & mask_byte;

where source_byte is the... source byte
and mask_byte is the mask
by performing a bitwise AND you can blank out specific bits
example:

if the mask were 11111111 (bits)
source_byte & mask_byte would = the original source_byte
(all 1s, no bits ANDed out)
if the mask were 11110000 (again, these are the bits)
source_byte & mask_byte would = xxxx0000 where x are the original bits from source_byte.

Any questions?

-Michael

Share this post


Link to post
Share on other sites