1
 private int ControlDecode(byte b) { int itype = -1; int ipacekttype = b & 0xF0; switch (ipacekttype) { case 0x40: if ((b & 0x0F) != 0x0F) itype = 0x45; else itype = 0x4F; break; case 0x50: itype = 0x45; break; case 0x00: itype = 0x00; break; case 0x80: itype = 0x89; break; case 0x90: itype = 0x89; break; default: break; } return itype; } 

If b=51, ipacekttype=48( according to code execution) but theoratically when masking we should get 50 as answer can anyone explain me how (b & 0xF0) works here please?

2
  • "when masking we should get 50" - How do you figure? decimal 51 = 0011 0011, bitwise and with 0xF0 (which is 1111 0000) = 0011 0000, which is indeed decimal 48. Commented Jul 27, 2016 at 13:05
  • @dasblinkenlight Thank yu Commented Jul 27, 2016 at 13:14

1 Answer 1

2

It looks like you are mixing decimal notation and hex notation. When you say b=51, it appears that 51 is decimal, so bn=0x33 in hex. This explains why ipacekttype=48 - again, in decimal, because it's ipacekttype=0x30 in hex, i.e. exactly what it is supposed to be after masking 0x33 with 0xF0.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.