binary inverse

  • Thread starter Thread starter boardmaker
  • Start date Start date
B

boardmaker

To make my life a little easier is there any way to get a binary numbe
to inverse. Example. 1110 in a1 so then b1 would become 0001
 
Public Function binverse(wCell As String) As String
Dim x, y As Integer
Dim nResult As String
nResult = vbNullString
x = Len(wCell)
For y = 1 To x
If Mid(wCell, y, 1) = "1" Then
nResult = nResult & "0"
Else
nResult = nResult & "1"
End If
Next
binverse = nResult
End Function




"boardmaker" <[email protected]>
schreef in bericht
news:[email protected]...
 
boardmaker said:
To make my life a little easier is there any way to get a binary number
to inverse. Example. 1110 in a1 so then b1 would become 0001.

One way would be =DEC2BIN(2^(LEN(A1))-1-BIN2DEC(A1),LEN(A1))
 
boardmaker said:
To make my life a little easier is there any way to get a binary number
to inverse. Example. 1110 in a1 so then b1 would become 0001.

I presume you mean one's complement, not inverse. And 0001 is the
complement of 1110 only in a 4-bit world.

The one's complement of a 4-bit binary number (in A1) can be computed
by:

=dec2bin(16 - bin2dec(A1) - 1, 4)
 
Back
Top