WizardsSleeve WizardsSleeve - 1 year ago 205
Vb.net Question

VB.NET bit shift confusion

I have some questions regarding VB.NET bit shifting. I understand the

<< >>
operators are bit shift operators in VB.NET.

I have a two-byte hex value,
, and each bit in these two bytes represents either a day, month or year. The bit structure of this hex value is
yyyy yyym mmmd dddd

I am confused as to how I should bit shift these values so that year, month and day are in their own
values. What should the shifting numbers be and do I need to add any padding to the shift?

Answer Source

You're going to need to use And as well as the bit shifting operations to get your result. You need to shift right (count the "non-year" bits for the amount) to get just the year. To get the day, just And with the value that has all the "day" bits set. Extracting the month will require a combination of the two techniques, either Anding then >> or >> and then Anding with the correct mask.


  • To extract the year: 0x3ACC >> 9
  • To extract the day: 0x3ACC And 0x001F
  • To extract the month: 0x3ACC And 0x01E0 >> 5
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download