|
-
Jun 5th, 2010, 03:59 PM
#1
Thread Starter
Addicted Member
[RESOLVED] MsgBox(256 >> 2) In VB6
Hi,
Im not sure how they call it, but I call it Binary rotation.
In VB.NET I can easily rotate numbers using something like this:
Code:
MsgBox(256 >> 2) '// Wich will return: "64".
But on VB6 It won't work, so I need to know if there is a function in vb6 that maybe I don't know about, that can replace the ">>" or "<<" ?
Please help, thanks.
 DoEvents
-
Jun 5th, 2010, 04:06 PM
#2
Re: MsgBox(256 >> 2) In VB6
There are no explicit left and right shift operators in VB6. You can use something like:
256 \ 4
Left and right rotate are entirely different things, and I don't think VB.Net even supports those.
-
Jun 5th, 2010, 04:16 PM
#3
Thread Starter
Addicted Member
Re: MsgBox(256 >> 2) In VB6
Umm.. I have a decryption algorithm in VB.NET that uses ">>" and "<<" everywhere, so I need to convert it in VB6.
I was thinking of converting numbers to binary string "010101" then rotate left/right, then convert to Long, but its verry slow. I need to know if there is an other way?
 DoEvents
-
Jun 5th, 2010, 04:33 PM
#4
Re: MsgBox(256 >> 2) In VB6
With some forms of decryption, rotation is used. I have a project on planetsourcecode that has a rotation algo you might want to look at.
-
Jun 5th, 2010, 06:28 PM
#5
Re: MsgBox(256 >> 2) In VB6
-
Jun 5th, 2010, 06:32 PM
#6
Re: MsgBox(256 >> 2) In VB6
In base 10, you can do *10, and often school children are taught the trick just add that many zeros. Thus 30*10 is 300, 20*100 is 2000, and so on. These are powers of 10. 10^1 and 10^2 respectively(and 10^3 is 1000).
Binary(base 2) works the same way with powers of 2. 2*2=4 which in binary is B10 to B100, 2*4(B10*B100) = 8(B1000), 2*8(B10*B1000) = 16(B10000), and so on. The same works with division, only removing digits.
To rotate, you can mask the bits with AND, and shift them(multiplication or division with powers of 2), then combine them back with OR.
For example, lets take the number(assuming type byte) 170, in binary that's B10101010. Now lets figure out how to rotate it. To create a bit mask for the AND portion, we'll take our power of two and subtract one. Lets say we want to shift it 2 bits to the right, that's 2^2 or 4(B100), subtract 1, gives us 3(B11), that's the mask we need. So then take (3 And 170), which is 2(B10). Now we need to shift that to align to the left side of a byte. 2^8 is 256, which would shift an entire byte. We need two bits less than that. So: 2^(8-2) is 2^6(which is 64). So then, we get:
vb Code:
ShiftRight = 4 'should be 1 to 7, ideally
lNumber = 171 'should be a byte 0-255
lNumber = (lNumber \ 2 ^ ShiftRight) Or (((2 ^ ShiftRight - 1) And lNumber) * 2 ^ (8 - ShiftRight))
' 'normal shift ' + 'create mask and apply it ' 'shift the masked bits'
Debug.Print lNumber
Again, this is only designed for Byte. Other types are going to be signed, and you'll have to deal with the sign bit.
Last edited by FireXtol; Jun 5th, 2010 at 07:01 PM.
Software I use and highly recommend: Opera, Miranda IM, Peerblock, Winamp, Unlocker Assistant, JoyToKey, Virtual CloneDrive, Secunia PSI, ExplorerXP, GOM Player, Real Alternative, Quicktime Alternative,Sumatra PDF, and non-freeware: Photoshop and VB6( ).
My codebank: AllRGB, Rounded Rectangle(math), Binary Server, Buddy Paint, LoadPictureGDI+, System GUID/Volume Serial, HexToAsc, List all processes and their paths, quasiString matching
Strings(search, extraction, retrieval etc): Retrieve BBCode Link from HTML, RemoveBetween ()'s, strFindBetween(str1,str2), Insert text in HTML, HTML - GetSpanByID
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|