473,378 Members | 1,394 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Bitwise shift in VB.Net 2002

How do you do a bit shift in VB.Net 2002?

In VB.Net 2003n you can use the << or >> operators.

Thanks

Rudolf
Nov 20 '05 #1
8 8399
Rudolf:

VB.NET 2002 doesnt support bitwise operators. Youll have to use binary
multiplication/division to get the job done.

"Rudolf" <Ru*****@Hotmail.com> wrote in message
news:17****************************@phx.gbl...
How do you do a bit shift in VB.Net 2002?

In VB.Net 2003n you can use the << or >> operators.

Thanks

Rudolf

Nov 20 '05 #2
Thanks,

I eventually ended up using
Private Function ShiftL(ByVal val As Integer, ByVal bits
As Integer) As Integer
If bits = 0 Then Return 0
Return CType(val / (2 ^ bits), Integer)
End Function

Rudolf
-----Original Message-----
Rudolf:

VB.NET 2002 doesnt support bitwise operators. Youll have to use binarymultiplication/division to get the job done.

"Rudolf" <Ru*****@Hotmail.com> wrote in message
news:17****************************@phx.gbl...
How do you do a bit shift in VB.Net 2002?

In VB.Net 2003n you can use the << or >> operators.

Thanks

Rudolf

.

Nov 20 '05 #3
Hi Rudolf,

There isn't a bitwise shift in VB.Net 2002. I think you can write your own
function to achieve this. Right shift 1 bit means divided by 2, while left
shift 1 bit means multiple by 2.

Hope this helps.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "Rudolf" <Ru*****@Hotmail.com>
| Sender: "Rudolf" <Ru*****@Hotmail.com>
| Subject: Bitwise shift in VB.Net 2002
| Date: Thu, 25 Sep 2003 00:18:34 -0700
| Lines: 7
| Message-ID: <17****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcODNTsnTE6O9BfXT1m1j0pcFAj32Q==
| Newsgroups: microsoft.public.dotnet.languages.vb
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:141046
| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| How do you do a bit shift in VB.Net 2002?
|
| In VB.Net 2003n you can use the << or >> operators.
|
| Thanks
|
| Rudolf
|

Nov 20 '05 #4
That should do it, although I would throw in some exception handling for
possible integer overflows.

Catch ex as OverflowException
' greater than 32 bit value - ack
"Rudolf" <Ru*****@Hotmail.com> wrote in message
news:10*****************************@phx.gbl...
Thanks,

I eventually ended up using
Private Function ShiftL(ByVal val As Integer, ByVal bits
As Integer) As Integer
If bits = 0 Then Return 0
Return CType(val / (2 ^ bits), Integer)
End Function

Rudolf
-----Original Message-----
Rudolf:

VB.NET 2002 doesnt support bitwise operators. Youll have

to use binary
multiplication/division to get the job done.

"Rudolf" <Ru*****@Hotmail.com> wrote in message
news:17****************************@phx.gbl...
How do you do a bit shift in VB.Net 2002?

In VB.Net 2003n you can use the << or >> operators.

Thanks

Rudolf

.

Nov 20 '05 #5
Hello,

"Rudolf" <Ru*****@Hotmail.com> schrieb:
How do you do a bit shift in VB.Net 2002?

In VB.Net 2003n you can use the << or >> operators.


http://groups.google.de/groups?selm=...ampabay.rr.com

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #6
Hi Rudolf,

Shift to the left:

Result = Number * (2 ^ (number of bits))

Shift to the right:

Result = Number \ (2 ^ (number of bits))

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"
"Rudolf" <Ru*****@Hotmail.com> wrote in message
news:17****************************@phx.gbl...
: How do you do a bit shift in VB.Net 2002?
:
: In VB.Net 2003n you can use the << or >> operators.
:
: Thanks
:
: Rudolf
Nov 20 '05 #7
Thanks
-----Original Message-----
That should do it, although I would throw in some exception handling forpossible integer overflows.

Catch ex as OverflowException
' greater than 32 bit value - ack


Nov 20 '05 #8
Hi Rudolf,

There's an important but very unobvious flaw in your routine!!

Private Function ShiftL_RealDiv (ByVal val As Integer, _
ByVal bits As Integer) As Integer
If bits = 0 Then Return 0
Return CType (val / (2 ^ bits), Integer)
End Function
vs
Private Function ShiftL_IntDiv (ByVal val As Integer, _
ByVal bits As Integer) As Integer
If bits = 0 Then Return 0
Return val \ CInt (2 ^ bits)
End Function

This is the output of a loop doing ShiftL (I, 1):

I = 0, ShiftL_Int = 0, ShiftL_Float = 0
I = 1, ShiftL_Int = 0, ShiftL_Float = 0
I = 2, ShiftL_Int = 1, ShiftL_Float = 1
I = 3, ShiftL_Int = 1, ShiftL_Float = 2 x
I = 4, ShiftL_Int = 2, ShiftL_Float = 2
I = 5, ShiftL_Int = 2, ShiftL_Float = 2
I = 6, ShiftL_Int = 3, ShiftL_Float = 3
I = 7, ShiftL_Int = 3, ShiftL_Float = 4 x
I = 8, ShiftL_Int = 4, ShiftL_Float = 4
I = 9, ShiftL_Int = 4, ShiftL_Float = 4
I = 10, ShiftL_Int = 5, ShiftL_Float = 5
I = 11, ShiftL_Int = 5, ShiftL_Float = 6 x
I = 12, ShiftL_Int = 6, ShiftL_Float = 6
I = 13, ShiftL_Int = 6, ShiftL_Float = 6
I = 14, ShiftL_Int = 7, ShiftL_Float = 7
I = 15, ShiftL_Int = 7, ShiftL_Float = 8 x

As you can see the integer division has the expected pairs while the
floating division produces singlets and triples.

The difference is due to the way that VB now rounds floating point
division to the nearest even number (round-to-even). It's to help with
accuracy in floating point arithmetic but it really screws things up when
doing integer arithmetic. It's one that you have to watch out for as it's a
real hidden bug producer. $%£&*!! on the person who decided that this was the
way to go.

Regards,
Fergus

ps. If bits = 0 Then Return 0
Why do you return 0? A shift of 0 bits should return the original number,
surely?
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Randell D. | last post by:
Why would one use bitwise operators? I can program in various languages in some shape or form (C++, PHP, some scripting) and I've heard/seen bitwise operators before, but never understood why...
3
by: sandy_pt_in | last post by:
Hi C guru's can you please tell me how to do multiplication of 2 numbers using bitwize operators?? expecting reply.
8
by: Paul E Collins | last post by:
Suppose I have a few Keys objects: Keys k1 = Keys.V; // V Keys k2 = Keys.Control | Keys.V; // Ctrl+V Keys k3 = Keys.Shift | Keys.J; // Shift+J I need to determine which of these include the...
4
by: kernelxu | last post by:
Hi,folks. I got some suggestion about bitwise shift from <The C Book, second edition>(written by Mike Banahan, Declan Brady and Mark Doran, originally published by Addison Wesley in 1991. This...
5
by: noridotjabi | last post by:
I'm learning to program in C and any tutorial or book that I read likes to briefly touch on birdies operators and then move on without giving any sort of example application of them. Call me what...
1
by: rabidusv | last post by:
As I understand it, the unsigned long type is 4 bytes. Also, the bitwise shift (<<) is a zero-fill shift as opposed to a rotational shift. However when I shift, the value seems to be rotating, as...
5
by: Gigs_ | last post by:
Can someone explain me bitwise expression? few examples for every expression will be nice x << y Left shift x >y Right shift x & y Bitwise AND x | y Bitwise OR x ^ y Bitwise XOR (exclusive...
29
by: Carl Banks | last post by:
Anyone with me here? (I know the deadline for P3 PEPs has passed; this is just talk.) Not many people are bit-fiddling these days. One of the main uses of bit fields is flags, but that's not...
5
by: Rahul | last post by:
Hi Everyone, I have a program unit which does >and << of an integer which is of 4 bytes length. The logic of shifting and action based on the result, assumes that the system is big-endian. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.