Bit shift operator worked in 4.2 but not in 4.3 - Netduino Plus 2 (and Netduino Plus 1) - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Bit shift operator worked in 4.2 but not in 4.3


  • Please log in to reply
3 replies to this topic

#1 Joshk

Joshk

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts

Posted 21 August 2016 - 06:27 PM

I was successfully using this code in the 4.2 framework to get the MAC address.  

    Private Function getMacAddress(ByVal seperator As String) As String
        Dim netIF As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
        Dim macAddress As String = ""
        ' Create a character array for hexidecimal conversion.'
        Const hexChars As String = "0123456789ABCDEF"
        ' Loop through the bytes.'
        For b As Integer = 0 To 5
            ' Grab the top 4 bits and append the hex equivalent to the return string.'
            macAddress += hexChars(netIF(0).PhysicalAddress(b) >> 4)
            ' Mask off the upper 4 bits to get the rest of it.'
            macAddress += hexChars(netIF(0).PhysicalAddress(b) And &HF)
            ' Add the dash only if the MAC address is not finished.'
            If b < 5 Then macAddress += seperator
        Next
        Return macAddress
    End Function

 

But after having to upgrade to 4.3 when I setup my new computer, the code-check underlines the code

netIF(0).PhysicalAddress(b) >> 4

and gives this error if I try to deploy:

Error 1 Type 'System.Nullable(Of )' is not defined.
 
If I remove the ">> 4" part of the line the code-check is happy.  So why is that operator not supported?  Do I need a special import now?


#2 JoopC

JoopC

    Advanced Member

  • Members
  • PipPipPip
  • 148 posts

Posted 22 August 2016 - 06:08 AM

do this:

'UShort * 2^8 for left shifting 8 bit (<< 8)
'UShort / 2^8 for right shifting 8 bit (>> 8)

' X * 2 ^ Y for << left shifting
' X / 2 ^ Y for >> right shifting

'so 4 << 7 = 4 * 2 ^ 7
'so 5 >> 3 = 5 / 2 ^ 3

#3 JoopC

JoopC

    Advanced Member

  • Members
  • PipPipPip
  • 148 posts

Posted 22 August 2016 - 06:59 AM

MAC address

Public Function MACaddress() As String
Dim macInDecs As Byte() = NetworkInterface.GetAllNetworkInterfaces(0).PhysicalAddress
Dim strMacAddress = ""
For t As Integer = 0 To macInDecs.Length - 1
strMacAddress &= If(t = 0, "", ".") & macInDecs(t).ToString("X2")
Next
Return strMacAddress

End Function

#4 Joshk

Joshk

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts

Posted 26 August 2016 - 03:24 AM

Thanks guys.  That looks like it will work, I will test it when I get a chance.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.