# Microsoft Office Application Help - Excel Help forum > Excel Programming / VBA / Macros >  >  Convert Binary to Hex

## Chipmunk

How to I convert a 32 bit binary number to hex?

----------


## Barb Reinhardt

Have you tried function BIN2HEX?

"Chipmunk" wrote:

> How to I convert a 32 bit binary number to hex?

----------


## Chipmunk

Yes.  I can do it with 8 digits and some others but i need to convert a 12
digit binary number to hex.  example:  cell f11 has:   010101010101   what i
have is =bin2hex(F11)  and it doesn work.

"Barb Reinhardt" wrote:

> Have you tried function BIN2HEX?
>
> "Chipmunk" wrote:
>
> > How to I convert a 32 bit binary number to hex?

----------


## Tom Ogilvy

=BIN2HEX(LEFT(B4,8))&BIN2HEX(RIGHT(B4,4))

--
regards,
Tom Ogilvy


"Chipmunk" wrote:

> Yes.  I can do it with 8 digits and some others but i need to convert a 12
> digit binary number to hex.  example:  cell f11 has:   010101010101   what i
> have is =bin2hex(F11)  and it doesn work.
>
> "Barb Reinhardt" wrote:
>
> > Have you tried function BIN2HEX?
> >
> > "Chipmunk" wrote:
> >
> > > How to I convert a 32 bit binary number to hex?

----------


## Chipmunk

Wonderful that works great.   Now the long pass....  Can we do it with a 32
bit binary number?

Thanks.

"Tom Ogilvy" wrote:

> =BIN2HEX(LEFT(B4,8))&BIN2HEX(RIGHT(B4,4))
>
> --
> regards,
> Tom Ogilvy
>
>
> "Chipmunk" wrote:
>
> > Yes.  I can do it with 8 digits and some others but i need to convert a 12
> > digit binary number to hex.  example:  cell f11 has:   010101010101   what i
> > have is =bin2hex(F11)  and it doesn work.
> >
> > "Barb Reinhardt" wrote:
> >
> > > Have you tried function BIN2HEX?
> > >
> > > "Chipmunk" wrote:
> > >
> > > > How to I convert a 32 bit binary number to hex?

----------


## Michel Pierron

Hi Chipmunk,

Function BinToHex(Binary As String)
Dim Value&, i&, Base#: Base = 1
For i = Len(Binary) To 1 Step -1
Value = Value + IIf(Mid(Binary, i, 1) = "1", Base, 0)
Base = Base * 2
Next i
BinToHex = Hex(Value)
End Function

MP

"Chipmunk" <Chipmunk@discussions.microsoft.com> a écrit dans le message de
news: 5273CEE1-742F-47B5-A14F-CAA8EAF83D10@microsoft.com...
> How to I convert a 32 bit binary number to hex?

----------


## Chipmunk

Thanks for the response.  I opened up the vb editor and pasted in your code.
What do I need to put in the worksheet cell?

Thanks.

"Michel Pierron" wrote:

> Hi Chipmunk,
>
> Function BinToHex(Binary As String)
> Dim Value&, i&, Base#: Base = 1
> For i = Len(Binary) To 1 Step -1
> Value = Value + IIf(Mid(Binary, i, 1) = "1", Base, 0)
> Base = Base * 2
> Next i
> BinToHex = Hex(Value)
> End Function
>
> MP
>
> "Chipmunk" <Chipmunk@discussions.microsoft.com> a Ã©crit dans le message de
> news: 5273CEE1-742F-47B5-A14F-CAA8EAF83D10@microsoft.com...
> > How to I convert a 32 bit binary number to hex?
>
>
>

----------


## Michel Pierron

Hi Chipmunk,
This code must be in a standard module.
In worksheet cell:
=
In ComboBox Functions: select Other functions
In ComboBox Categories: Select Personalized
In ListBox Functions: Select BinToHex

Regards,
MP

"Chipmunk" <Chipmunk@discussions.microsoft.com> a écrit dans le message de
news: E3D25622-043D-4705-9201-B04C8B88726F@microsoft.com...
> Thanks for the response.  I opened up the vb editor and pasted in your
> code.
> What do I need to put in the worksheet cell?
>
> Thanks.
>
> "Michel Pierron" wrote:
>
>> Hi Chipmunk,
>>
>> Function BinToHex(Binary As String)
>> Dim Value&, i&, Base#: Base = 1
>> For i = Len(Binary) To 1 Step -1
>> Value = Value + IIf(Mid(Binary, i, 1) = "1", Base, 0)
>> Base = Base * 2
>> Next i
>> BinToHex = Hex(Value)
>> End Function
>>
>> MP
>>
>> "Chipmunk" <Chipmunk@discussions.microsoft.com> a écrit dans le message
>> de
>> news: 5273CEE1-742F-47B5-A14F-CAA8EAF83D10@microsoft.com...
>> > How to I convert a 32 bit binary number to hex?
>>
>>
>>

----------


## davitz38

I use this online binary to hex converter to make sure I convert the right way
Pretty cool!
David

----------

