Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 17th, 2004, 07:39 AM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default integer overflow

Hello!

I am trying to modify the bits of an integer (16 bits). What I want to do is to change the 16th bit of that number. So I am doing the following:

MyNumber = MyNumber Or LShift(1, 15) where LShift is the following function:

Public Function LShift(ByVal Value As Integer, _
                                 Count As Integer) As Integer
Dim i As Integer

  If Count = 0 Then
    LShift = Value
    Exit Function
  End If

  LShift = Value

  For i = 1 To Count
    LShift = LShift * 2
  Next

End Function

The problem is that as soon as the counter gets to 15, the function returns an overflow. So the maximun number I get is 16384. Is there another way to do this?

Thanks,

Paul
Reply With Quote
  #2 (permalink)  
Old March 17th, 2004, 08:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

The usual way to set the nth bit is just to 'Or' the current value with 2^(n-1), but VB's 16-bit integers are signed so the hi-bit (16th bit) denotes the sign. The easiest way to change the sign of an Int is to * -1.
Reply With Quote
  #3 (permalink)  
Old March 17th, 2004, 09:01 AM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks mate!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Overflow grstad Classic ASP Databases 18 December 14th, 2006 10:06 AM
regarding Overflow of variable hiruni Access VBA 4 February 27th, 2006 02:17 PM
Overflow Error mateenmohd Classic ASP Basics 4 July 5th, 2005 02:12 AM
Buffer Overflow rekha_jsr Oracle 3 February 3rd, 2005 08:11 PM
can anybody tell why i am getting overflow error tulsi15 SQL Server 2000 1 December 15th, 2004 07:58 AM



All times are GMT -4. The time now is 06:36 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.