|
-
Jan 10th, 2004, 11:57 PM
#1
Thread Starter
Fanatic Member
Port Java to Vb6
Greetings... I'm in the process of converting an encryption algorithm from Java to VB. but first I'd like to better grasp the concepts behind the Java routines.
from what I can see, the java routines take in a string such as
#58#54#58#42#50#
and returns the string
~b#9#XZ?›aÅXÞ
JAVA:
Code:
private void s(String s1)
{
private final String b_java_lang_String_array1d_fld[] = { "LHKf24()", "..FWSqw1", "783vcSWr", "NSW%FGS3", "S834VS$!"};
StringTokenizer stringtokenizer = new StringTokenizer(s1 + "#", "#");
BitSet bitset = new BitSet(64);
for(int i1 = 0; i1 < 5; i1++)
{
BitSet bitset1 = a(b_java_lang_String_array1d_fld[i1].toCharArray());
int j1 = Integer.parseInt(stringtokenizer.nextToken());
for(int l1 = 0; l1 < j1; l1++)
bitset1 = a(bitset1);
bitset.xor(bitset1);
}
char ac[] = a(bitset, 8);
for(int k1 = 0; k1 < 8; k1++)
if(ac[k1] == 0 || ac[k1] == '\n' || ac[k1] == '\r')
ac[k1] = (char)(ac[k1] | 0x80);
try
{
a_java_io_DataOutputStream_fld.writeBytes("~b#9#");
for(int i2 = 0; i2 < ac.length; i2++)
a_java_io_DataOutputStream_fld.write((byte)(ac[i2] & 0xff));
a_java_io_DataOutputStream_fld.writeBytes("\n");
}
catch(Exception exception)
{
a(1);
}
}
private BitSet a(BitSet bitset)
{
BitSet bitset1 = new BitSet(64);
boolean flag = false;
for(int i1 = 0; i1 < 64; i1++)
{
if(flag != bitset.get(i1))
bitset1.set(i1);
flag = bitset.get(i1);
}
return bitset1;
}
private BitSet a(char ac[])
{
int i1 = ac.length * 8;
BitSet bitset = new BitSet(i1);
for(int j1 = 0; j1 < i1; j1++)
{
int k1 = j1 & 7;
int l1 = j1 >> 3;
if((ac[l1] & 0xff & 1 << 7 - k1) != 0)
bitset.set(j1);
}
return bitset;
}
private char[] a(BitSet bitset, int i1)
{
int j1 = i1 * 8;
char ac[] = new char[i1];
for(int k1 = 0; k1 < j1; k1++)
{
int l1 = k1 & 7;
int i2 = k1 >> 3;
if(bitset.get(k1))
ac[i2] = (char)(ac[i2] | 1 << 7 - l1);
}
return ac;
}
I would like to produce the same effects in VB, but I'm having trouble grasping the concepts behind how it encrypts/decrypts the strings.
is this some form of bitset conversion? or mere string/character shift conversion?
another string passed through the function is
#58#32#59#48#26#
which returns
~b#20#àž-Un†„
any ideas on this concept would be greatly appreciated.
Last edited by TokersBall_CDXX; Feb 1st, 2004 at 03:28 PM.
-
Jan 11th, 2004, 01:27 AM
#2
Addicted Member
What are you using to comple your java. My TextPad gives me an error.
Quis Custodiet Ipsos Custodes?
You don't have to be faster than the bear, you just have to be faster than the slowest person running from the bear.
-
Jan 11th, 2004, 01:28 AM
#3
Thread Starter
Fanatic Member
I use the compiler from Java.Sun
SDK 4
it's an applet of course
-
Jan 11th, 2004, 01:29 AM
#4
Thread Starter
Fanatic Member
this is prolly what's causing the error
private final String b_java_lang_String_array1d_fld[] = { "LHKf24()", "..FWSqw1", "783vcSWr", "NSW%FGS3", "S834VS$!"};
I pulled it out of main
-
Jan 11th, 2004, 01:37 AM
#5
Addicted Member
hmmm...im as stumped as you are
Quis Custodiet Ipsos Custodes?
You don't have to be faster than the bear, you just have to be faster than the slowest person running from the bear.
-
Jan 11th, 2004, 01:38 AM
#6
Addicted Member
Do you need the same method of encryption in VB or do you just want to know how to do a deep encrytion in VB?
Quis Custodiet Ipsos Custodes?
You don't have to be faster than the bear, you just have to be faster than the slowest person running from the bear.
-
Jan 11th, 2004, 01:40 AM
#7
Thread Starter
Fanatic Member
hmm
I am familular with many methods of encryption in vb
how ever I've been trying to convert this to particular method into vb and it has had me stumped for months
-
Jan 11th, 2004, 01:45 AM
#8
Addicted Member
I'll look over it tomorrow, my eyes are getting heavy. Maby a nights sleep will open my mind...I'll keep working on it though.
Quis Custodiet Ipsos Custodes?
You don't have to be faster than the bear, you just have to be faster than the slowest person running from the bear.
-
Jan 11th, 2004, 11:34 AM
#9
Thread Starter
Fanatic Member
-
Jan 11th, 2004, 05:45 PM
#10
Thread Starter
Fanatic Member
-
Jan 11th, 2004, 08:31 PM
#11
The code you posted seems to be only the encryption method.
Also it encrypts strings only in that format ie: #num#num#num#num#num#...
The code can be converted, with a little more code in vb than in Java, but, yes, it is possible. Your gonna have to re-create the BitSet class in VB, the rest is about the same. For the StringTokenizer class in Java, you can use the equivalent of Split in VB.
I don't see where this function is being used:
private BitSet a(char ac[]).... ??
And I don't understand this part of the code:
catch(Exception exception)
{
a(1);
}
There is no "a" function that takes an integer, and why would you call it if it does not use the retun value ?
-
Jan 12th, 2004, 06:20 PM
#12
Thread Starter
Fanatic Member
-
Jan 12th, 2004, 06:32 PM
#13
Elaborate what ? everything ? i'm not gonna do it...
Tell me what you don't understand from what I wrote, and I'll try to elaborate...
-
Jan 12th, 2004, 06:35 PM
#14
Thread Starter
Fanatic Member
what kind of encryption method is this?
and is it possible to recreate the Bitset class in VB6 (not .NET)
if so do you know of any documention on the Bitset class that demonstrates it's lower level functionality?
-
Jan 12th, 2004, 06:47 PM
#15
"what kind of encryption method is this?"
No idea, i've never seen an encryption like this... but as I mentioned before, it encrypts ONLY string in that format #num#num...
"is it possible to recreate the Bitset class in VB6 (not .NET)"
Yes, it is possible
"...do you know of any documention ...."
No, i personally don't... but I'm sure you can find something in google.com
It is not that difficult to figure out what the BitSet class does... from the name you can see that it has to do with Bits, from it's use you can see that it's implementing an XOR function, a Get function, and a copy contructor. If you look more carefully how is each one used you can see what they return, and also you can figure out how it works...
-
Jan 12th, 2004, 06:53 PM
#16
Thread Starter
Fanatic Member
-
Jan 12th, 2004, 06:56 PM
#17
Thread Starter
Fanatic Member
Question
would this function be the start on my venture through the lands of bits and bytes?
VB Code:
Public Function BitSet(Number As Long, ByVal Bit As Long) As Long
If Bit = 31 Then
Number = &H80000000 Or Number
Else
Number = (2 ^ Bit) Or Number
End If
BitSet = Number
End Function
-
Jan 12th, 2004, 07:59 PM
#18
Use AND not OR...
What you want is to get the bit at that position, so if you do somehing like:
01110011101010111 OR
00000000010000000
---------------------------
01110011111010111
but you want something like this:
01110011101010111 AND
00000000010000000
---------------------------
00000000000000000
In this case the bit at that position is 0, so the whole thing will be 0
Get it ?
-
Jan 12th, 2004, 08:03 PM
#19
But you have to make a class, not a function...
Do you know how to make a class ?, do you know what's the difference ?
-
Jan 13th, 2004, 03:13 PM
#20
Thread Starter
Fanatic Member
hmm
well I've been trying to come up with a way to mimic the bitset class in JAVA, this is as close as I can get but I'm still sketchy in certain areas.
VB Code:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Bit_Vec"
Attribute VB_Creatable = True
Attribute VB_Exposed = True
Option Explicit
DefInt A-Z
Const CLASS_NAME = "Bit_Vec"
Const CLASS_VERSION = "100"
Const vbErrSubscriptOutOfRange = 9
Const BITS_PER_ELEMENT = 8
Private mBits() As Byte
Private mNumElements As Long
Private Sub Class_Initialize()
End Sub
Private Sub Class_Terminate()
Erase mBits
End Sub
Public Property Let NumElements(NewValue As Long)
mNumElements = NewValue
ReDim Preserve mBits(mNumElements \ BITS_PER_ELEMENT)
End Property
Public Property Get NumElements() As Long
NumElements = mNumElements
End Property
'------------------------------------------------------
'-- METHODS
'------------------------------------------------------
Public Sub ClearAll()
Dim i As Long
'-- Set bit values in BITS_PER_ELEMENT chunks for speed
For i = LBound(mBits) To UBound(mBits)
mBits(i) = &H0
Next i
End Sub
Public Sub ClearBit(Index As Long)
'-- Set Bit(Index) value to 0
Dim ArrayIdx As Long
Dim Bit As Long
Call ValidateIndex(Index)
ArrayIdx = Index \ BITS_PER_ELEMENT
Bit = Index Mod BITS_PER_ELEMENT
'Debug.Print "Clearing ArrayIdx:"; ArrayIdx, " Bit:"; Bit
mBits(ArrayIdx) = mBits(ArrayIdx) And (Not (2 ^ Bit))
End Sub
Public Function GetBit(Index As Long) As Integer
'-- Returns 0 or 1
Call ValidateIndex(Index)
If IsBitSet(Index) Then
GetBit = 1
Else
GetBit = 0
End If
End Function
Public Function IsBitSet(Index As Long) As Boolean
Dim ArrayIdx As Long
Dim Bit As Long
Call ValidateIndex(Index)
ArrayIdx = Index \ BITS_PER_ELEMENT
Bit = Index Mod BITS_PER_ELEMENT
'Debug.Print "Testing ArrayIdx:"; ArrayIdx, " Bit:"; Bit
If mBits(ArrayIdx) And 2 ^ Bit Then
IsBitSet = True
Else
IsBitSet = False
End If
End Function
Public Sub SetAll()
Dim i As Long
'-- Set bit values in BITS_PER_ELEMENT chunks for speed
For i = LBound(mBits) To UBound(mBits)
mBits(i) = &HFF
Next i
End Sub
Public Sub SetBit(Index As Long)
'-- Set Bit(Index) value to 1
Dim ArrayIdx As Long
Dim Bit As Long
Call ValidateIndex(Index)
ArrayIdx = Index \ BITS_PER_ELEMENT
Bit = Index Mod BITS_PER_ELEMENT
'Debug.Print "Setting ArrayIdx:"; ArrayIdx, " Bit:"; Bit
mBits(ArrayIdx) = mBits(ArrayIdx) Or 2 ^ Bit
End Sub
Public Sub ToggleBit(Index As Long)
'-- Toggle the value of Bit(Index)
Call ValidateIndex(Index)
If IsBitSet(Index) Then
Call ClearBit(Index)
Else
Call SetBit(Index)
End If
End Sub
Private Sub ValidateIndex(Index As Long)
'-- Our bounds checking code is aware that this is
' a 0 based array of bits.
If (Index < 0) Or (Index > (mNumElements - 1)) Then
RaiseError vbErrSubscriptOutOfRange
End If
End Sub
'------------------------------------------------------
'-- ERRORS
'------------------------------------------------------
' .GetErrorDesc
Private Function GetErrorDesc(ErrCode As Long) As String
Dim Desc As String
Select Case ErrCode
Case vbErrSubscriptOutOfRange
Desc = "Subscript out of Range"
Case Else
Desc = "Unknown error"
End Select
GetErrorDesc = Desc
End Function
' .RaiseError
Private Sub RaiseError(ErrCode As Long)
Err.Raise Number:=vbObjectError + ErrCode, _
Source:=CLASS_NAME & " " & CLASS_VERSION, _
Description:=GetErrorDesc(ErrCode)
End Sub
any major problems you see that I am missing or not thinking of or may have missed??
-
Jan 13th, 2004, 06:56 PM
#21
Well, if you make the ValidateIndex sub into a function you can get rid of GetErrorDesc and RaiseError
do something like:
VB Code:
Private Function IsValidIndex(Index As Long) As Boolean
'-- Our bounds checking code is aware that this is
' a 0 based array of bits.
IsValidIndex = Not (Index < 0 Or Index >= mNumElements)
End Function
Also, I don't see where you set the data into the array, and remember that it comes from a string, so use StrConv function
I'm talking about this line from java code:
BitSet bitset1 = a(b_java_lang_String_array1d_fld[i1].toCharArray());
Also have a way to XOR 2 classes, from java code: bitset.xor(bitset1);
Everything else looks OK, but i did not actually test anything.
-
Jan 13th, 2004, 07:03 PM
#22
Actually, nevermind about ValidateIndex thing... took a second look at your code, and i changed my mind, it is better how you did it...
-
Jan 13th, 2004, 07:59 PM
#23
Thread Starter
Fanatic Member
hmm
I'm having trouble setting the data into an array... and I'm finding that the standard XOR function is not being friendly with me.
-
Jan 13th, 2004, 08:25 PM
#24
For the StrConv:
VB Code:
Dim Buffer() As Byte
Buffer = StrConv("blah", vbFromUnicode)
For the XOR, post the code so I can see what's wrong
-
Jan 13th, 2004, 10:01 PM
#25
Thread Starter
Fanatic Member
hmm
Code:
BitSet bitset1 = a(b_java_lang_String_array1d_fld[i1].toCharArray());
appears to call the function
Code:
private BitSet a(char ac[])
{
int i1 = ac.length * 8;
BitSet bitset = new BitSet(i1);
for(int j1 = 0; j1 < i1; j1++)
{
int k1 = j1 & 7;
int l1 = j1 >> 3;
if((ac[l1] & 0xff & 1 << 7 - k1) != 0)
bitset.set(j1);
}
return bitset;
}
in order to translate the character array (string) into a bitset return
I've tried recreating this function to no end with no luck
I'm stuck at
Code:
int l1 = j1 >> 3;
if((ac[l1] & 0xff & 1 << 7 - k1) != 0)
bitset.set(j1);
how does ones tranlate this into vb?
-
Jan 13th, 2004, 10:12 PM
#26
int l1 = j1 >> 3;
if((ac[l1] & 0xff & 1 << 7 - k1) != 0)
bitset.set(j1);
Bit shifting...
It's basicly division/multiplication of 2 ^ "shift by"
So... j1 >> 3 would be j1 \ 8
Note that I used \ not /, because it returns an integer instead of decimal (double)
if((ac[l1] & 0xff & 1 << 7 - k1) != 0)
would be translated to:
If ac(l1) And &HFF And 128 - k1) <> 0 Then
....
0xff -> &HFF or 255
1 << 7 -> 2 ^ 7 -> 128
-
Jan 13th, 2004, 10:16 PM
#27
Thread Starter
Fanatic Member
hmm something like this?
VB Code:
Private Function BitShift(ac As String)
Dim i1 As Integer
Dim TempBitSet1 As New BitVector
i1 = Len(ac) * 8
TempBitSet1.NumElements i1
For j1 = 0 To i1
Dim k1 As Integer
Dim l1 As Integer
k1 = j1 & 7
l1 = j1 \ 8
If ac(l1) And &HFF And 128 - k1 <> 0 Then TempBitSet1.SetBit (j1)
Next a
BitShift = TempBitSet1
End Function
-
Jan 13th, 2004, 10:56 PM
#28
3 things...
First, when you return a reference, do not dim with the new keyword in the same line... because at the end of the function the vb environment will destroy the variables (and it's references)
Second, is partially my mistake too, the if statement is in brackets
Third, don't Dim inside loops, don't really know why, but it's a good practice to Dim all variables at the beginning of the sub/function
VB Code:
Private Function BitShift(ac As String) As BitVector
Dim i1 As Integer
Dim k1 As Integer
Dim l1 As Integer
Dim TempBitSet1 As BitVector
Set TempBitSet1 = New BitVector
i1 = Len(ac) * 8
TempBitSet1.NumElements i1
For j1 = 0 To i1
k1 = j1 & 7
l1 = j1 \ 8
If (ac(l1) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit (j1)
Next a
Set BitShift = TempBitSet1
End Function
The rest looks ok... again, I did not actually run the code to test it...
-
Jan 13th, 2004, 11:03 PM
#29
Also... i just noticed... ac is a string...
VB Code:
Private Function BitShift(ac() As Byte) As BitVector
Dim i1 As Integer
Dim k1 As Integer
Dim l1 As Integer
Dim TempBitSet1 As BitVector
Set TempBitSet1 = New BitVector
i1 = Len(ac) * 8
TempBitSet1.NumElements i1
For j1 = 0 To i1
k1 = j1 & 7
l1 = j1 \ 8
If (ac(l1) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit j1
Next a
Set BitShift = TempBitSet1
End Function
or
VB Code:
Private Function BitShift(ac As String) As BitVector
Dim i1 As Integer
Dim k1 As Integer
Dim l1 As Integer
Dim TempBitSet1 As BitVector
Set TempBitSet1 = New BitVector
i1 = Len(ac) * 8
TempBitSet1.NumElements i1
For j1 = 0 To i1
k1 = j1 & 7
l1 = j1 \ 8
If (Asc(Mid(ac, l1 + 1, 1)) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit j1
Next a
Set BitShift = TempBitSet1
End Function
-
Jan 13th, 2004, 11:30 PM
#30
Thread Starter
Fanatic Member
-
Jan 13th, 2004, 11:36 PM
#31
Thread Starter
Fanatic Member
I think
VB Code:
Dim i1 As Integer
Dim k1 As Integer
Dim l1 As Integer
Dim TempBitSet1 As BitVector
Set TempBitSet1 = New BitVector
i1 = Len(ac) * 8
TempBitSet1.NumElements = i1
For j1 = 0 To i1
k1 = j1 & 7
l1 = j1 \ 8
If (Asc(Mid(ac, l1 + 1, 1)) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit (j1)
Next j1
Set BitShift = TempBitSet1
End Function
the k1=j1 & 7 is causing a problem
it appears to equal 647 at the time of the error flag
should that be + 7? or is this another operation taking place?
-
Jan 13th, 2004, 11:38 PM
#32
ow... & is And (binary and to be more precice) but in vb it kinda knows when to use the boolean and or binary and
so
k1 = j1 & 7
is
k1 = j1 And 7
-
Jan 14th, 2004, 11:07 PM
#33
Thread Starter
Fanatic Member
hmm
well in terms of the BitShift function I was able to port it with a great deal of your help, thank you.
JAVA
Code:
private BitSet a(char ac[])
{
int i1 = ac.length * 8;
BitSet bitset = new BitSet(i1);
for(int j1 = 0; j1 < i1; j1++)
{
int k1 = j1 & 7;
int l1 = j1 >> 3;
if((ac[l1] & 0xff & 1 << 7 - k1) != 0)
bitset.set(j1);
}
return bitset;
}
in VB
VB Code:
Private Function BitShift(ac As String) As BitVector
Dim i1 As Integer
Dim k1 As Integer
Dim l1 As Integer
Dim TempBitSet1 As BitVector
Set TempBitSet1 = New BitVector
i1 = Len(ac) * 8
TempBitSet1.NumElements = i1
Do While j1 < i1
k1 = j1 & 7
l1 = j1 \ 8
Debug.Print l1
If l1 < 8 Then If (Asc(Mid(ac, l1 + 1, 1)) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit (j1)
j1 = j1 + 1
Loop
Set BitShift = TempBitSet1
End Function
how ever I can't quite grasp how I'm going to pass one class to another.. is this possible in vb?
VB Code:
Private Sub cmdTest1_Click()
Dim BitSet1 As New BitVector
BitSet1.NumElements = 64
HashArray() = Split("LHKf24(),..FWSqw1,783vcSWr,NSW%FGS3,S834VS$!", ",")
BitSet1 = BitShift(HashArray(0))
End Sub
'Object doesn't support this method.
Last edited by TokersBall_CDXX; Jan 14th, 2004 at 11:12 PM.
-
Jan 15th, 2004, 06:46 PM
#34
Thread Starter
Fanatic Member
-
Jan 15th, 2004, 07:02 PM
#35
Why do you always create a class like this:
Dim BitSet1 As New BitVector ?
When you create a variable of new instance of a class in the same line, the variable is like a static variable, you can't change it, the BitSet1 will always point to the class instance that was created at that moment.
But... if you create a class like this:
Dim BitSet1 As BitVector
You create a reference, and taht means that that reference can point to any instance of a class of that type (BitVector).
So, for your code to work properly, you have to do something like this:
VB Code:
Private Sub cmdTest1_Click()
Dim BitSet1 As BitVector
BitSet1.NumElements = 64
HashArray() = Split("LHKf24(),..FWSqw1,783vcSWr,NSW%FGS3,S834VS$!", ",")
Set BitSet1 = BitShift(HashArray(0))
End Sub
In order of execution, you create a reference to the class in cmdTest
You call the function BitShift, where it also creates a reference of the same type of class, in the function you create a new instance of the class and you put it in TempBitSet1 reference, then you pass that reference as a return value. When the function is complete, it will NOT distroy the class because it was created as a reference, and also because you return the reference.
When the BitShift function is complete and returns the reference, the reference gets copyed in the BitSet1 variable using the Set keyword. after that, you can use that reference because the class is still not distroyed, but instead it's location (the reference) was moved from one variable to another... as long as one variable has it's reference, the class is still in the memory, and can be used...
Get it ?
-
Jan 15th, 2004, 07:14 PM
#36
Also, since the BitSet1 variable does not contain a reference to any class, you will get an error at this line:
BitSet1.NumElements = 64
VB Code:
Private Sub cmdTest1_Click()
Dim BitSet1 As BitVector
HashArray() = Split("LHKf24(),..FWSqw1,783vcSWr,NSW%FGS3,S834VS$!", ",")
Set BitSet1 = BitShift(HashArray(0))
End Sub
-
Jan 15th, 2004, 08:33 PM
#37
Thread Starter
Fanatic Member
wow you ROCK!
okay so far I have this
VB Code:
Private Sub cmdTest1_Click()
Dim BitSet1 As BitVector
Dim HashArray() As String
Dim ParsedNumArray() As String
Dim i1, jtemp, j1 As Integer
HashArray() = Split("LHKf24(),..FWSqw1,783vcSWr,NSW%FGS3,S834VS$!", ",")
ParsedNumArray() = Split("58#54#58#42#50#", "#")
For i1 = 0 To 4
Set BitSet1 = BitShift(HashArray(i1))
For jtemp = 0 To UBound(ParsedNumArray()) - 1
j1 = Int(ParsedNumArray(jtemp))
Set BitSet1 = BitFlag(BitSet1)
Next jtemp
Next i1
End Sub
Private Function BitShift(ac As String) As BitVector
Dim i1 As Integer
Dim k1 As Integer
Dim l1 As Integer
Dim TempBitSet1 As BitVector
Set TempBitSet1 = New BitVector
i1 = Len(ac) * 8
TempBitSet1.NumElements = i1
For j1 = 0 To i1
k1 = j1 & 7
l1 = j1 \ 8
If l1 <> 8 Then If (Asc(Mid(ac, l1 + 1, 1)) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit (j1)
Print
Next j1
Set BitShift = TempBitSet1
End Function
Private Function BitFlag(BitSet As BitVector) As BitVector
Dim BitSet1 As BitVector
Dim Flag As Boolean
Dim i1 As Integer
Set BitSet1 = New BitVector
BitSet1.NumElements = 64
Flag = False
For i1 = 0 To 63
If Flag <> BitSet.GetBit(CLng(i1)) Then BitSet1.SetBit (CLng(i1))
Flag = BitSet.GetBit(CLng(i1))
Next i1
Set BitFlag = BitSet1
End Function
see anything out of place? it's not producing any errors which is good
on to the next function to port
Code:
private char[] a(BitSet bitset, int i1)
{
int j1 = i1 * 8;
char ac[] = new char[i1];
for(int k1 = 0; k1 < j1; k1++)
{
int l1 = k1 & 7;
int i2 = k1 >> 3;
if(bitset.get(k1))
ac[i2] = (char)(ac[i2] | 1 << 7 - l1);
}
return ac;
}
you mentioned earlier that the >> is a 2^ equation?
would that mean i2 = k1 >> 2^3 ?
thanx for your help you rock!
-
Jan 15th, 2004, 08:38 PM
#38
>> ( right shift ), in VB you divide
<< ( left shift ), in VB you multiply
So
i2 = k1 >> 3;
In VB is
i2 = k1 \ 2^3
or
i2 = k1 \ 8
-
Jan 15th, 2004, 08:53 PM
#39
Thread Starter
Fanatic Member
hmm
something about this port seems odd
I screwed it up
Code:
private char[] a(BitSet bitset, int i1)
{
int j1 = i1 * 8;
char ac[] = new char[i1];
for(int k1 = 0; k1 < j1; k1++)
{
int l1 = k1 & 7;
int i2 = k1 >> 3;
if(bitset.get(k1))
ac[i2] = (char)(ac[i2] | 1 << 7 - l1);
}
return ac;
}
VB Code:
Private Function Characterize(BitSet As BitVector, i1 As Integer) As String
Dim ji, k1, l1, i2 As Integer
Dim ac As String
j1 = i1 * 8
For k1 = 0 To j1
l1 = k1 & 7
i2 = k1 \ 8
If BitSet.get(k1) Then ac = ac Or 1 * 7 - l1
Next k1
Characterize = ac
End Function
-
Jan 15th, 2004, 09:15 PM
#40
You need to learn how to deal with strings also....
VB Code:
Private Function Characterize(BitSet As BitVector, i1 As Integer) As String
Dim ji, k1, l1, i2 As Integer
Dim ac As String
' int j1 = i1 * 8;
j1 = i1 * 8
' char ac[] = new char[i1];
ac = String(i1, 0)
' for(int k1 = 0; k1 < j1; k1++)
' j1 is not included
For k1 = 0 To j1 - 1
' int l1 = k1 & 7;
' & in VB is AND, I mentioned that in a previous post also
l1 = k1 And 7
' int i2 = k1 >> 3;
i2 = k1 \ 8
' if(bitset.get(k1)) ac[i2] = (char)(ac[i2] | 1 << 7 - l1);
' ac[i2], is getting a particular character, not the entire string !
If BitSet.get(k1) Then
Mid$(ac, i2 + 1, 1) = Chr(Asc(Mid$(ac, i2 + 1, 1)) Or 128 - l1)
' The index for Mid function is starting at 1, that's why I did "i2 + 1"
End If
Next k1
Characterize = ac
End Function
And also, you made the same mistake with this: 1 << 7
In one of the previous posts I converted a line wich contained 1 << 7, and I wrote 128...
To make this clear, I'll do it step by step...
So... 1 << 7
In vb is:
1 * 2 ^ 7
or
1 * 128
or
128
Last edited by CVMichael; Jan 15th, 2004 at 09:20 PM.
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
|