Simon

Here we go, Binary Arithmetic 101 :)

Data is stored in bytes, each byte is made up of 8 bits which represent the

powers of 2 from 0 to 7, therefore a single byte can represent numbers from

0 - 255, a 2 byte number, VB Integer, can hold, using only positive values,

numbers from 0 - 32767, a 4 byte number, VB Long, 0 - 2147483647.

Now using just Byte data, the bits are

4 = 00000100 = 2 ^ 2

3 = 00000011 = 2 ^ 0 + 2 ^ 1

With the bit representation you read from right to left, so the right most

digit is 2 ^ 0 and the left most digit is 2 ^ 7.

Using just binary, this can only have 1 of 2 values, either 0 or 1, when you

mask 2 numbers it can only return 1 if both bits are 1, so when you bit mask

3 And 4

00000100

00000011

------------------

00000000

To look at each bit pair, from left to right

0 And 0 = 0, 0 And 0 = 0, 0 And 0 = 0, 0 And 0 = 0

0 And 0 = 0, 1 And 0 = 0, 0 And 1 = 0, 0 And 1 = 0

If you bit mask 3 & 5

00000011

00000101

-----------------

00000001

0 And 0 = 0, 0 And 0 = 0, 0 And 0 = 0, 0 And 0 = 0

0 And 0 = 0, 1 And 0 = 0, 0 And 1 = 0, 1 And 1 = 1

A good demonstration of this is determining if a number is Odd or Even

Function IsEven(Num) As Boolean

IsEven = Num And 1

End Function

When doing the If Len(strOpenFileName) Then, what this is doing is

VB True = -1 which in Binary is 1111111111111111

On Windows 32 platforms the maximum length of the path is 259, so if you had

a path that was that long the binary string would be

000000100000011

which when masked against True gives

000000100000011

111111111111111

---------------------------------

000000100000011

which is not 0 and therefore Not False

Conversely, if a zero length string is returned then

0000000000000000

1111111111111111

-----------------------------------

0000000000000000

regards

Ian

** invalid email address, change dk to denmark

homepage http://www.kingsoft-denmark.com/

Tips & Tricks page http://tips.kingsoft-denmark.com/

Quote:

> Heh, for this part (well, one line of it) - "WHOOSH" :)

> > Now if you're checking 2 string lengths you do need to use the operator,

> > i.e.

> > If Len(strOpenFileName1) > 0 And Len(strOpenFileName2) > 0 Then

> > This is because of the way And works, it actually masks the bits of the

> > return values, so in the above we're checking for a bit comparison of 2

> > Boolean results, but if you write it as

> > If Len(strOpenFileName1) And Len(strOpenFileName2) Then

> > and use strOpenFileName1 = "abc" and strOpenFileName2 = "abcd", even

> though

> > both strings are not zero length, the comparison will return False

because

> > when you do a bit mask of 3

> What determines the "bit mask" i.e. in this case, what determines that the

> bit mask in this case is 3?

> >... and 4 - 0000100

> Why "(4 - )"? and why 0000100 instead of 0000011?

> >no bits match

> you mean that when the expression 4 - 0000100 is evaluated, the result is

> not equivalent to 0000011?

> The message did clear up the problem, thanks again Ian, and also Martin

> Trump, for continued help

> Cheers

> Simon Yu