Excel VBA - strings for hex logical operations

strange_steve

New Member
Joined
Jun 30, 2015
Messages
1
I have a VBA conditional function I hacked together (I'm a noob) that does a hex 'AND" function on a 36-bit value in a cell with another 36-bit value.

This result is then passed though another function (total hack) that looks for logical '0' other wise it assumes logic '1'. The second part is clunky but works

The problem seem to be in the first function "HexBitAND", which appears to work but when I hit the 32bit boundary the "HexBitAND" function stops working (bit positions 0-31 work fine positions 32-35 do not) perhaps someone can please advise.

Here are the functions:

Function HexBitAND(N1 As String, N2 As String) As String
HexBitAND = Hex$(Val("&H" & N1) And Val("&H" & N2))
End Function


I have attached the second part of the function as additional info:

Function IsZeroOrOne(N1 As String) As String
If N1 = "0" Then
IsZeroOrOne = "0"
Else
IsZeroOrOne = "1"
End If
End Function

Function ZeroOne(N1 As String, N2 As String) As String
ZeroOne = IsZeroOrOne(HexBitAND(N1, N2))
End Function

The main issue is in the HexBitAND function I think the problem is with the "type"

Function HexBitAND(N1 As String, N2 As String) As String
HexBitAND = Hex$(Val("&H" & N1) And Val("&H" & N2))
End Function

For instance :

bit30: N1=FFFFFFCCF N2=040000000 Result = 40000000

bit31: N1=FFFFFFCCF N2=080000000 Result = 80000000

bit32: N1=FFFFFFCCF N2=100000000 Result = 0

bit33: N1=FFFFFFCCF N2=200000000 Result = 0

Thoughts anyone?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,216,119
Messages
6,128,947
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top