Do

BinaryToDec = BinaryToDec + (Left(BinaryValue, 1) * 2 ^ (Len(BinaryValue) - 1))

BinaryValue = Mid(BinaryValue, 2)

Loop Until BinaryValue = ""

End Function

byteA = BinaryToDec("11011111") Xor BinaryToDec("11111111")

Solved

Posted on 2005-04-18

I am using VB6 doing bit manipulation

The values of the individual bits correspond to a specific action needed to be performed or to knowledge of equipment status.Example byte 11101000 the last 0 may mean that a piece of equipment is on. The program sending the string of bytes inverts (XOR's) the bit values of some but not all bytes. I wanted to XOR the byte and get the orginal byte so I wrote the following:

byteA = 11111111 Xor byteA 'byteA = 11011111 in this example

my result is 102112

I expected 00100000

I thought I was given the decimal value, however it converts to 11000111011100000 as binary

How do I get the Xor'ed byte as my result

Thanks Terry

The values of the individual bits correspond to a specific action needed to be performed or to knowledge of equipment status.Example byte 11101000 the last 0 may mean that a piece of equipment is on. The program sending the string of bytes inverts (XOR's) the bit values of some but not all bytes. I wanted to XOR the byte and get the orginal byte so I wrote the following:

byteA = 11111111 Xor byteA 'byteA = 11011111 in this example

my result is 102112

I expected 00100000

I thought I was given the decimal value, however it converts to 11000111011100000 as binary

How do I get the Xor'ed byte as my result

Thanks Terry

9 Comments

Do

BinaryToDec = BinaryToDec + (Left(BinaryValue, 1) * 2 ^ (Len(BinaryValue) - 1))

BinaryValue = Mid(BinaryValue, 2)

Loop Until BinaryValue = ""

End Function

byteA = BinaryToDec("11011111") Xor BinaryToDec("11111111")

I am very new to this so I must ask:

1. how does this code work?

2. how do I add it to my code?

3. Will it give me the binary 8 bit string I need later in the program?

4. can I substitue a variable like byteA = BinaryToDec(byteA) Xor BinaryToDec("11111111")

Terry

Anyone that can help make this more clear will receive extra points. Please note that byteA will always be changing. It is to be compared to a byte 11111111 which will be constant. As noted in my first post I need to receive the inverted byte in return not a dec value.

byteA = byteA Xor &HFF

stringA = binString(byteA)

Function binString(N As Long) As String

Do While N > 0

a = a + CStr(N Mod 2)

N = N \ 2

Loop

a = StrReverse(a)

g = Len(a)

If g < 8 Then

t = String$(8 - Len(a), "0")

a = t + a

End If

binString = a

End Function

ByteA as string 'if I use byte I get overflow errors

ByteA = 11011111 'for this example, it will always be different

InvbyteA = Not byteA 'I inserted your suggestion and I got -11011112 as my result

Any idea why this is happen? Any good books on byte and bit manipulation with VB6? I have not had time to try "ozo's" most recent solution.

Thanks Terry

ba1 = Left(byteA, 1)

ba1 = ba1 Xor 1

ba2 = Mid(byteA, 2, 1)

ba2 = ba2 Xor 1

ba3 = Mid(byteA, 3, 1)

ba3 = ba3 Xor 1

ba4 = Mid(byteA, 4, 1)

ba4 = ba4 Xor 1

ba5 = Mid(byteA, 5, 1)

ba5 = ba5 Xor 1

ba6 = Mid(byteA, 6, 1)

ba6 = ba6 Xor 1

ba7 = Mid(byteA, 7, 1)

ba7 = ba7 Xor 1

ba8 = Mid(byteA, 8, 1)

ba8 = ba8 Xor 1

InvbyteA = ba1 & ba2 & ba3 & ba4 & ba5 & ba6 & ba7 & ba8

By clicking you are agreeing to Experts Exchange's Terms of Use.

Title | # Comments | Views | Activity |
---|---|---|---|

has22 challenge | 11 | 56 | |

factory design pattern vs abstract factoy design pattern | 2 | 63 | |

Batch file output | 20 | 71 | |

wordsWithoutList challenge | 24 | 61 |

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**15** Experts available now in Live!