working with bits

S

s gall

Hi all
I have a task to test a checksum algrorithum. This requires changing a
string of 12 chr's to a stream of 96 bits and then manipulating these.
Currently I work in vb (vb2008). Would it be better for me to use another
language (say vc++) and build a DLL to do the bit manipulating or does
vb.net have some way of working with bits.

Stephen
 
G

Gillard

if the manipulation is easy to do there is a converter from decimal to
binary

Public Function DecToBin(ByVal DecVal As Double) As String
Dim a As Double
a = DecVal
For b = 1 To Int(Log(DecVal) / Log(2)) + 1
DecToBin = CDbl(a Mod 2) & DecToBin
a = CDbl(Int(a / 2))
Next b
End Function
 
B

Bill McCarthy

Hi Stephen,

VB supports the standard bitwise operations Or, And, Not and XOr as well as
bit shifting >> for right shift, and << for left shift.
One thing to be aware of, there is no type character for byte, so for
constants you have to write CByte(&HFF) or similar.
You can get the string into an array of bytes like so:

Dim b(0 To 7) As Byte
For i As Int32 = 0 To 7
b(i) = CByte(Asc(keyString(i)) And &H80)
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top