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

Bitwise operations in VB

VB bitwise operations

  • Please log in to reply
1 reply to this topic

#1 sHINE

sHINE

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationHamburg, Germany

Posted 01 January 2013 - 10:02 PM

Hi there!

 

As an old vb.net programmer I just reloaded my old netduino classic with the latest Firmware and start writing some test-programs to control my led-matrix mentioned in another thread.

 

However, I'm stuck at the following code:

 

Public Sub SetBit(ByRef byteToAlter As Byte, bitPosition As Integer, bitValue As Integer)        Select Case bitValue            Case 1                Dim mask As Byte = 1 << bitPosition 'if bitPosition is 3, mask results in 00001000                 byteToAlter = byteToAlter Or mask            Case 0                Dim mask As Byte = 255 - (1 << bitPosition) ' if bitPosition is 3, mask results in 11110111                 byteToAlter = byteToAlter And mask        End Select    End Sub

 

 

This one works fine in VB.net (full Framework) but not in MF. 1 << bitposition is not supported.

If I try to write this part in c# (1 <<= bitPosition) it works as expected.

 

But I don't want to write the entire stuff in c# (hmm, might be better :)) so it must be possible to do this sort of bitshifting in vb.

 

Thanks and regards

 

Jan



#2 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 04 January 2013 - 02:59 AM

Hi Jan,

It works ok for me using firmware 4.2.0.1

	Dim byteToAlter As Byte = 0        Debug.Print("byteToAlter = " & byteToAlter.ToString)        SetBit(byteToAlter, 3, 1)        Debug.Print("byteToAlter = " & byteToAlter.ToString)  '--> 8        SetBit(byteToAlter, 3, 0)        Debug.Print("byteToAlter = " & byteToAlter.ToString)  '--> 0        Debug.Print((247 And 8).ToString)               byteToAlter = 247        SetBit(byteToAlter, 3, 1)        Debug.Print("byteToAlter = " & byteToAlter.ToString) '--> 255        Debug.Print((247 Or 8).ToString)

Baxter







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.