Maximum PC

 It is currently Tue Sep 16, 2014 4:52 pm

 All times are UTC - 8 hours

 Page 1 of 1 [ 10 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: I need to do a bit shift in VB6...Posted: Wed Jul 28, 2004 9:06 am
 INFINITE vCORE

Joined: Mon Jun 14, 2004 6:16 am
Posts: 467
Location: Middletown, DE
I am in need of the code that would be the equivalent of << 8 in VB.Net...

I know VB6 doesn't have this operator built in, and I know multiplying by 256 couldn't possibly be the solution...

If anyone has any tips, I would appreciate it.

Top

 Post subject: Posted: Wed Jul 28, 2004 9:17 am
 INFINITE vCORE

Joined: Mon Jun 14, 2004 6:16 am
Posts: 467
Location: Middletown, DE
I think I found it...and it looks like it is multiplying by 256...

Function ShiftRight(ByVal lngNumber as Long, ByVal intNumBits as Integer) as Long
'--------------
'BIT SHIFT RIGHT
'--------------

ShiftRight = lngNumber \ 2^intNumBits 'note the integer division op

End Function

Function ShiftLeft(Byval lngNumber as Long, ByVal intNumBits as integer) as Long
'--------------
'BIT SHIFT LEFT
'--------------

ShiftLeft = lngNumber * 2^intNumBits

End Function

Top

 Post subject: Posted: Wed Jul 28, 2004 9:23 am
 Professional Dork

Joined: Tue May 25, 2004 12:44 pm
Posts: 1246
Location: Cornhole County
What the hell are you trying to do there? I don't understand this <<8 moon language you're using.

Top

 Post subject: Posted: Wed Jul 28, 2004 9:29 am
 INFINITE vCORE

Joined: Mon Jun 14, 2004 6:16 am
Posts: 467
Location: Middletown, DE
HK-47 wrote:
What the hell are you trying to do there? I don't understand this <<8 moon language you're using.

I am helping a friend with a project, and we need to read a certain registry key, chop it up, decode it, then display it in a more familiar format...

It involves a bitshift and turning 15 'digits' into 25 'digits'... the original app is coded in VB6...so have to find a way to bit shift in VB6.

Yummy, huh?

Top

 Post subject: Re: I need to do a bit shift in VB6...Posted: Wed Jul 28, 2004 11:50 am
 Bitchin' Fast 3D Z8000

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 985
Location: Earth
defkhan1 wrote:
I am in need of the code that would be the equivalent of << 8 in VB.Net...

I know VB6 doesn't have this operator built in, and I know multiplying by 256 couldn't possibly be the solution...

If anyone has any tips, I would appreciate it.

Hope this helps:

Code:
Option Explicit

Private m_lPower2(0 To 31) As Long

Public Function RShift(ByVal lThis As Long, ByVal lBits As Long) As Long
If (lBits <= 0) Then
RShift = lThis
ElseIf (lBits > 63) Then
' .. error ...
ElseIf (lBits > 31) Then
RShift = 0
Else
If (lThis And m_lPower2(31 - lBits)) = m_lPower2(31 - lBits) Then
RShift = (lThis And (m_lPower2(31 - lBits) - 1)) * m_lPower2(lBits) Or m_lPower2(31)
Else
RShift = (lThis And (m_lPower2(31 - lBits) - 1)) * m_lPower2(lBits)
End If
End If
End Function

Public Function LShift(ByVal lThis As Long, ByVal lBits As Long) As Long
If (lBits <= 0) Then
LShift = lThis
ElseIf (lBits > 63) Then
' ... error ...
ElseIf (lBits > 31) Then
LShift = 0
Else
If (lThis And m_lPower2(31)) = m_lPower2(31) Then
LShift = (lThis And &H7FFFFFFF) \ m_lPower2(lBits) Or m_lPower2(31 - lBits)
Else
LShift = lThis \ m_lPower2(lBits)
End If
End If
End Function

Public Sub Init()
m_lPower2(0) = &H1&
m_lPower2(1) = &H2&
m_lPower2(2) = &H4&
m_lPower2(3) = &H8&
m_lPower2(4) = &H10&
m_lPower2(5) = &H20&
m_lPower2(6) = &H40&
m_lPower2(7) = &H80&
m_lPower2(8) = &H100&
m_lPower2(9) = &H200&
m_lPower2(10) = &H400&
m_lPower2(11) = &H800&
m_lPower2(12) = &H1000&
m_lPower2(13) = &H2000&
m_lPower2(14) = &H4000&
m_lPower2(15) = &H8000&
m_lPower2(16) = &H10000
m_lPower2(17) = &H20000
m_lPower2(18) = &H40000
m_lPower2(19) = &H80000
m_lPower2(20) = &H100000
m_lPower2(21) = &H200000
m_lPower2(22) = &H400000
m_lPower2(23) = &H800000
m_lPower2(24) = &H1000000
m_lPower2(25) = &H2000000
m_lPower2(26) = &H4000000
m_lPower2(27) = &H8000000
m_lPower2(28) = &H10000000
m_lPower2(29) = &H20000000
m_lPower2(30) = &H40000000
m_lPower2(31) = &H80000000
End Sub

Souce: http://www.vbaccelerator.com/home/VB/Tips/Implementing_Unsigned_Right_and_Left_Shift_Operators/article.asp

Top

 Post subject: Posted: Wed Jul 28, 2004 11:56 am
 Bitchin' Fast 3D Z8000

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 985
Location: Earth
HK-47 wrote:
What the hell are you trying to do there? I don't understand this <<8 moon language you're using.

In C/C++, you can shift the bits of a value type. In an 8-bit system, you may have something like:

00000000 = 0 (in integer)

If I were to apply << 1 or left-shift 1 bit, then I would get:

0000001 = 1
If I were to apply another left shift, then would get:

0000010 = 2

In essence, you're shifting the bits of a variable by some number (typicall less than or equal to the bit size of the type you're dealing with) to get another number, when you bit shift, you're in essence incrementing your variable by powers of 2.

Right shifts are the same:

10000000 = 128

If I right-shift by 1, >> 1

01000000 = 64

So now, with a right shift, you're decrementing by powers of 2.

Anyhow, most C/C++, Java, and C# programmers know this by heart.[/code]

Top

 Post subject: Re: I need to do a bit shift in VB6...Posted: Wed Jul 28, 2004 4:47 pm
 Bitchin' Fast 3D Z8000*

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
defkhan1 wrote:
I am in need of the code that would be the equivalent of << 8 in VB.Net...

I know VB6 doesn't have this operator built in, and I know multiplying by 256 couldn't possibly be the solution...

If anyone has any tips, I would appreciate it.

Multiplying by 256 is correct.* The reason becomes pretty obvious with an example....

Say we want to bitshift the binary number 001001, which is 9 in decimal.
1*2^3 + 1*2^0 = 8 + 1 = 9

A single shift to the left is 010010, which is 18 in decimal.
1*2^4 + 1*2^1 = 16 + 2 = 18

A second shift gives us 100100, which is 1*2^5 + 1*2^2 = 25 + 4 = 29.

As you can see, the a simple left or right shift is in fact just multiplying or dividing by 2, so <<8 is in fact the equivalent of number*2^8.

* A word of caution though, there are several different types of shifts and you need to be clear about which kind you need..... 1001 <2 = 100100 or 0101 or 0100 w/ the overflow bit set, etc depending on what kind of shift. I don't know VB, but I imagine the <<8 is a normal shift and not a rotate, still you might want to look into what happens with an overflow.

Top

 Post subject: Posted: Wed Jul 28, 2004 4:51 pm
 Bitchin' Fast 3D Z8000*

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
defkhan1 wrote:
HK-47 wrote:
What the hell are you trying to do there? I don't understand this <<8 moon language you're using.

I am helping a friend with a project, and we need to read a certain registry key, chop it up, decode it, then display it in a more familiar format...

It involves a bitshift and turning 15 'digits' into 25 'digits'... the original app is coded in VB6...so have to find a way to bit shift in VB6.

Yummy, huh?

Are you turning 15 digits into 25 digits or 15 bits into 25 bits? If you doing the former, you're going to want to multiply by 10^10, but you're also probably going to overflow the var. If the latter, instead of bit shifting, you could multiply by 2^10 or convert to string and append "0000000000" convert back, etc.

Top

 Post subject: Posted: Thu Jul 29, 2004 5:26 am
 INFINITE vCORE

Joined: Mon Jun 14, 2004 6:16 am
Posts: 467
Location: Middletown, DE
We already have the code to "extract" the 25 characters from the 15 Byte values, we just needed to do a simple shift 8 bits left on each byte before running it through the 'extraction' module...

Anyone guessed what we're doing yet?

Hint:
reg.ReadRemoteValue("MACHINENAME", HKEY_LOCAL_MACHINE, "XXXmagic keyXXXXX", "SOFTWARE\Microsoft\Windows NT\CurrentVersion")

Top

 Post subject: Posted: Sat Jul 31, 2004 8:14 pm
 Bitchin' Fast 3D Z8000*

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Not quite sure what you're up to... give us an example. Did that 2^num_shifts thing work out for you?

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 10 posts ]

 All times are UTC - 8 hours

Who is online

Users browsing this forum: No registered users and 3 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ Maximum FAQs    Forum Rules, Posting Guidelines & Announcements    The Good, The Bad & The Banned    FAQs Help/Do It Yourself    PC Building Lab    The Help Desk    PC Modding    Education & Certification Hardware    Nuts & Bolts    Portable Talk    Appraisals, Deals & Bargains (oh my!) OS/Software/Programming    Windows Parlor    Alt.OS.Abode    Games Arena    Programmers' Paradise Networking/Internet    Internet Truckstop    Network Nook In/Out    Magazine and Book Feedback    Forum & Website Feedback    Dog Pound Team Maximum PC Folding at Home    Team Maximum PC - Folding at Home - FIND CURES TO DISEASES    Team MPC - Folding Gauntlets