How to add the missing byte shifter operators to a vb.net - Visual Basic Support - 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

How to add the missing byte shifter operators to a vb.net

create dll shifter operators c# in VB

  • Please log in to reply
5 replies to this topic

#1 David Weaver

David Weaver

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts
  • LocationBloomington IL

Posted 06 February 2015 - 05:48 PM

How to add the missing byte shifter operators to a vb.net Netduino Project

 

  1. Start a new Netduino C# project
  2. Locate the projects properties page and select the target framework your vb.net project will be using mine was 4.2. Next change the “Output Type” to “Class Library”.
  3. Locate the main menu item “Build” and find the “Configuration manager. Then change the configuration from debug to release. This will allow you to build a dll you can use in all your projects in debug mode you would need many more files.
  4. Add a code file to the project and remove the program.cs file

 Add this code to it:

 

using System;

namespace ByteShifter

{

    public class ByteShifter

    {

      

        public  byte ShiftRight(byte bytetoshift, int placestoshift)

        {

 

            byte ShiftedByte = (byte)(bytetoshift >> placestoshift);

 

            return ShiftedByte;

        }

 

        public byte ShiftLeft(byte bytetoshift, int placestoshift)

        {

 

            byte ShiftedByte = (byte)(bytetoshift << placestoshift);

            return ShiftedByte;

        }

    }

}

 

  1. Build the solution and locate the release directory under solution directory the new dll should be there.
  2. Start of vb.net project and add a reference to the dll just created (I like to copy the dll to the vb.net debug directory and then add a reference to the vb.net project).
  3. Below is an example of how to use the new byte shifting functions in the dll you created

 

Imports Microsoft.SPOT

Imports Microsoft.SPOT.Hardware

Imports SecretLabs.NETMF.Hardware

Imports SecretLabs.NETMF.Hardware.Netduino

Imports ByteShifter 'new byte shifter functions

 

 

 

Module Module1

 

    Sub Main()

        'Create an object

        Dim obj As New ByteShifter.ByteShifter

 

        'Dim b As Byte = 8 >> 2

        Dim b As Byte = obj.ShiftRight(8, 2)

    'output should be 2

        Debug.Print("The 8 >> 2 answer is: " & b.ToString)

          

 

        Dim b1 As Byte = 155

        ' Dim b2 As Byte = b1 >> 1

        Dim b2 As Byte = obj.ShiftRight(b1, 1)

        'output should be 77

        Debug.Print("The answer for b2 is: " & b2.ToString)

 

        Dim b3 As Byte = 154

        'Dim b2 As Byte = b1 << 1

        Dim b4 As Byte = obj.ShiftedLeft(b3, 1)

        'output should be 52

        Debug.Print("Left Shifted b4 is:" & b4.ToString)

    End Sub

 

End Module

 

 

 



#2 scardinale

scardinale

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationNew York, USA

Posted 06 February 2015 - 11:17 PM

Simpler yet is to add these two extension methods to your project.
 

<System.Runtime.CompilerServices.Extension> _
Public Shared Function RightShift(integerToShift As Integer, bitsToShift As Integer) As Integer
    Return CInt(integerToShift / 2 ^ bitsToShift)
End Function

<System.Runtime.CompilerServices.Extension> _
Public Shared Function LeftShift(integerToShift As Integer, bitsToShift As Integer) As Integer
    Return CInt(integerToShift * 2 ^ bitsToShift)
End Function


#3 David Weaver

David Weaver

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts
  • LocationBloomington IL

Posted 07 February 2015 - 12:30 AM

Thank you for the solution you are right this is far better!!!



#4 David Weaver

David Weaver

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts
  • LocationBloomington IL

Posted 07 February 2015 - 12:44 AM

I just tried adding the code and got a bunch of errors could you give me an example of how to implement the functions thanks for the help in advance.



#5 David Weaver

David Weaver

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts
  • LocationBloomington IL

Posted 07 February 2015 - 01:58 AM

OK long day works great!!



#6 scardinale

scardinale

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationNew York, USA

Posted 07 February 2015 - 02:10 AM

Glad you got it working. That's what the community is about, sharing knowledge.






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.