EXCEL XOR multiple bits

后端 未结 5 2129
[愿得一人]
[愿得一人] 2021-02-20 05:33

Okay I have two cells with a string of bits 0111010 and 0101011. I want to XOR the two together so that the resulting cell would be 0010001.

I know you can use this for

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-20 05:53

    ' this VBA returns a double that has to be formatted on the worksheet.

    Option Explicit
    Public Function MYXOR(r1 As Range, r2 As Range) As Double
    'r1 and r2 are expected as HEX; for example, 
    'DEC2HEX(CODE("B")) returns ASCII of "B" as HEX
    On Error GoTo ErrHandler
      MYXOR = "&H" & r1.Value Xor "&H" & r2.Value
      GoTo CleanUp
    ErrHandler:
      MYXOR = Err.Number
      Resume CleanUp
    CleanUp:
    ' format the double being returned in MYXOR with TEXT(DEC2HEX(MYXOR(C9,F9)),"00000")
    ' number of leading zeroes according to the size of the HEX in r1 and r2
    End Function
    

提交回复
热议问题