How to obtain the Least-significant bits of a number

0

I wonder if it's possible to obtain the Least-significant bits of a number.

Example :

 uint intValue = Int32.MaxValue;
 uint LSB = intValue & 0x0000FFFF;

from :

https://www.oreilly.com/library/view/c-cookbook/0596003390/ch01s06.html

but I need this in VB.net.

I tried :

 Dim intValue As UInteger = 39101
 Dim LSB As UInteger = intValue And &HFFFF

Any idea?

.net
vb.net
hex
asked on Stack Overflow Apr 3, 2019 by Julien • edited Apr 3, 2019 by Visual Vincent

1 Answer

0

This should help you visualize what is going on. It shows various masks. Look at 'bits' at every Stop.

    Dim bits As String
    Dim intValue As UInteger = 39101
    Dim LSB As UInteger
    bits = Convert.ToString(intValue, 2).PadLeft(32, "0"c)
    Stop
    LSB = intValue And &HFFFFUI 'keep 16 bits
    bits = Convert.ToString(LSB, 2).PadLeft(32, "0"c)
    Stop
    LSB = intValue And &HFFUI 'keep 8 bits
    bits = Convert.ToString(LSB, 2).PadLeft(32, "0"c)
    Stop
    LSB = intValue And &HFUI 'keep 4 bits
    bits = Convert.ToString(LSB, 2).PadLeft(32, "0"c)
answered on Stack Overflow Apr 3, 2019 by dbasnett

User contributions licensed under CC BY-SA 3.0