We help IT Professionals succeed at work.

How to clear a nibble?

howardsd
howardsd asked
on
I'd like  to clear the most significant nibble of a byte??

So far I'm using:

      b1 = 0xC8;
        b2 = b1 << 4;
      b2 = b2 >> 4;

I want to end up with 0x08.

There's got to be a more slick method.
Comment
Watch Question

Hi howardsd,

you can simply use a AND bit-operation, i.e.:

> b2 = b1 & 0xf;

Hope that helps,

ZOPPO

Author

Commented:
Thanks.