Hex ANDing in Excel and / or Visual Basic

I am trying AND put two hexadecimal numbers in Excel/Visual Basic .

Ex. 53FDBC AND 00FFFF , which should give 00FDBC .

Any ideas on how to do this?

+4
source share
3 answers

I assume that you have 2 values ​​stored as strings. In this case, you can do the following:

 Dim hex1 As String hex1 = "53FDBC" Dim hex2 As String hex2 = "00FFFF" Dim bin1 As String bin1 = CLng("&H" & hex1) Dim bin2 As String bin2 = CLng("&H" & hex2) Dim result As String result = Hex$(bin1 And bin2) 

The result now contains "FDBC", but you can put it to the left with zeros

As a function (excel module) this can be implemented as:

 Function hexand(hex1 As String, hex2 As String) as String Dim bin1 As String bin1 = CLng("&H" & hex1) Dim bin2 As String bin2 = CLng("&H" & hex2) hexand = Hex$(bin1 And bin2) End Function 
+6
source

iirc, it is built-in, only bit offset operators are not built-in

& H53FDBC & & H00FFFF

0
source

The value of the hexadecimal value 0xFFFF in decimal value is 65536 the hexadecimal value of 0x53FDBC in decimal format is 5504444

So you can use = DEC2HEX (MOD (5504444,65536))

0
source

All Articles