For example I want to invert the 1st, 3rd, 5th and 7th bit of this byte 01010101 the resulting byte must be 11111111 since the 1st, 3rd, 5th and 7th bit has been inverted..
I've already seen this code provided by yytsunamiyy but it seems like there is a problem with the code. Here is the code that he had worked on:
from (http://www.mrexcel.com/forum/showthread.php?t=482910)
Code:
Public Function INVERTBITS(Source As Range, bits_to_invert As String) As String
Dim i As Integer
Dim store As String, x as string
For i = 1 To Len(Source.Value)
x = i
If InStr(bits_to_invert, x) > 0 Then
If Mid(Source.Value, i, 1) = "0" Then
store = store & "1"
Else
store = store & "0"
End If
Else
store = store & Mid(Source.Value, i, 1)
On Error GoTo 0
End If
Next i
INVERTBITS = store
End Function
And here is how it should work:
Usage:
Source-Byte Result Formula in B
110 011 =INVERTBITS(A2;"13")
010 111 =INVERTBITS(A3;"13")
11111111 01010101 =INVERTBITS(A4;"1357")
I need all of your help, thanks..
I've already seen this code provided by yytsunamiyy but it seems like there is a problem with the code. Here is the code that he had worked on:
from (http://www.mrexcel.com/forum/showthread.php?t=482910)
Code:
Public Function INVERTBITS(Source As Range, bits_to_invert As String) As String
Dim i As Integer
Dim store As String, x as string
For i = 1 To Len(Source.Value)
x = i
If InStr(bits_to_invert, x) > 0 Then
If Mid(Source.Value, i, 1) = "0" Then
store = store & "1"
Else
store = store & "0"
End If
Else
store = store & Mid(Source.Value, i, 1)
On Error GoTo 0
End If
Next i
INVERTBITS = store
End Function
And here is how it should work:
Usage:
Source-Byte Result Formula in B
110 011 =INVERTBITS(A2;"13")
010 111 =INVERTBITS(A3;"13")
11111111 01010101 =INVERTBITS(A4;"1357")
I need all of your help, thanks..