VS 2002 + bitshift the number by 8 bits

Posted on 2005-03-28
Medium Priority
Last Modified: 2010-04-23
I am trying a FTP class from Microsoft website, and am using VS 2002, there is one section as seen below.  It doesn't work.

I have tried this code on a different machine with VS 2003 and it works fine, so it looks like the code to muliple the number by 2 ot the power of 8 is working.

        ' Make this call in Visual Basic .NET 2002. You want to
        ' bitshift the number by 8 bits. In Visual Basic .NET 2002 you must
        ' multiply the number by 2 to the power of 8.
        Dim port As Int32 = port = parts(4) * (2 ^ 8)

        ' Make this call and then comment out the previous line for Visual Basic .NET 2003.
        'Dim port As Int32 = port = parts(4) << 8

Can i do this some other way.
Question by:dkilby
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 12

Expert Comment

ID: 13644055
I might be missing something but couldn't you use this instead

Dim port As Int32 = parts(4) * (2 ^ 8)

That should be a valid line assuming the value in "parts(4)" is a number.

LVL 96

Expert Comment

by:Bob Learned
ID: 13644127
What other way are you looking for?


Author Comment

ID: 13644174
I tried using Dim port As Int32 = parts(4) * (2 ^ 8) in VS 2002 and it comes back with a value of 0, it doesn't seem to work, because it doesnt return a valid port to connect to.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 13644196
just stepped through and this is the value

parts(4) = 249

port = 249 * (2 ^ 8)

after the calculation port = 0
LVL 12

Expert Comment

ID: 13644200
If it's returning 0 (i.e. assigning 0 to port)... then your problem is in the parts(4) as far as i know... because that is a legit assignment.

So if this code works in VS 2003 and not in 2002.. there is something not working with the assignment to the parts array in the different versions of VS (that sounds confusing)
LVL 12

Expert Comment

ID: 13644202
ok... will double check with mine
LVL 12

Accepted Solution

S-Twilley earned 2000 total points
ID: 13644222
Im running VB.NET 2002... and this works alright for me:

        Dim port As Int32
        Dim parts(5) As Int32
        parts(4) = 249

        port = parts(4) * (2 ^ 8)


What is the parts array declared as in your code

Author Comment

ID: 13644261
very strange, when i use the code above it works, but if i use the one line it doesnt

oh well however it works is all i need.

LVL 12

Expert Comment

ID: 13644280
No problem...  maybe the second pair of eyes helped :P

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question