Click here to Skip to main content
15,898,373 members
Articles / Programming Languages / Visual Basic
Tip/Trick

How to Add the Missing Byte Shifter Operators to a VB.NET Netduino Project

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Feb 2015CPOL 13.5K   4
How to add the missing byte shifter operators to a VB.NET Netduino Project

Introduction

This tip will show you how to add the missing byte shifter operators to a VB.NET Netduino project. The steps are as given below:

  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:

    VB.NET
    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;
            }
        }
    }
  5. Build the solution and locate the release directory under solution directory. The new DLL should be there.
  6. 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).
  7. Below is an example of how to use the new byte shifting functions in the DLL you created.
    VB.NET
    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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer David Weaver Consulting
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionWhy bother! Pin
Mr Ed (Auckland,NZ)13-Feb-15 0:22
Mr Ed (Auckland,NZ)13-Feb-15 0:22 
Questionbtw Pin
trkchk12-Feb-15 7:35
trkchk12-Feb-15 7:35 
AnswerOT: Reply to direct email message Pin
OriginalGriff17-Jul-15 20:33
mveOriginalGriff17-Jul-15 20:33 
Hi Dave!

Sorry to reply here: the only way to reply to a direct message is via email, which passes on the email address. I'm a little particular about who I give my email to – I get hundreds of emails I have to read every day already – so I'm replying here so as not to pass it on at this stage. No offence is intended – but I don’t know who the heck you are! Laugh | :laugh:

The first thing to notice is that no article gets through without review anyway – moderation takes a number of members to say “yes” or “no” before it goes public, and that can include comments on the style, content and usefulness of the content.

But it sounds like you want more than that – you want “peer review” of the content before anyone gets to see it, and that’s difficult because you need lots of people to read it in order to pass back useful feedback.

I’d suggest that the best way to do this would be finish the article, post it for moderation and see what feedback you get once it’s published. You can always edit your article after publication at any time, so getting it perfect can be as a result of the feedback you get on it – and you potentially get a much wider range of readers that way, moderation can take only a handful.

Remember, you don't have to link your resume to it until you are happy with it! I look forward to reading it. Thumbs Up | :thumbsup:
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: OT: Reply to direct email message Pin
trkchk27-Sep-17 11:03
trkchk27-Sep-17 11:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.