Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Hex2Bin in VB

I was just wondering if there was some code or function that exists to
convert hex to binary in vB. My program takes a 8 bytes of hex and converts
them to binary populating each Bit in a column (64 columns). I need an easy
way instead of using more columns to perform the HEX2BIN worksheet function.

thanks
Josh

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 339
Default Hex2Bin in VB


"kuch68" wrote in message
...
I was just wondering if there was some code or function that exists to
convert hex to binary in vB. My program takes a 8 bytes of hex and

converts
them to binary populating each Bit in a column (64 columns). I need an

easy
way instead of using more columns to perform the HEX2BIN worksheet

function.

thanks
Josh


There is a HEX2BIN function available in the Analysis toolpak add-in.

/Fredrik


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Hex2Bin in VB

=Hex2bin("2b")

displays

101011

You have to have the analysis toolpak installed.

If that isn't the answer, then you need to restate your question in a
different way so we can understand it.

--
Regards,
Tom Ogilvy

"kuch68" wrote in message
...
I was just wondering if there was some code or function that exists to
convert hex to binary in vB. My program takes a 8 bytes of hex and

converts
them to binary populating each Bit in a column (64 columns). I need an

easy
way instead of using more columns to perform the HEX2BIN worksheet

function.

thanks
Josh



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Hex2Bin in VB

My mistake, what I am looking for is a conversion in my code instead of
populating columns. Something along the lines of

HexValueInput = Cells(i,j).value
BinaryRepresentation = Bin(HexValueInput)

Where Bin is a function to convert within my code. Can I use HEX2BIN there
like:

BinaryRepresentation = HEX2BIN(HexValueInput) ?

thanks again for your help
Josh




"Tom Ogilvy" wrote:

=Hex2bin("2b")

displays

101011

You have to have the analysis toolpak installed.

If that isn't the answer, then you need to restate your question in a
different way so we can understand it.

--
Regards,
Tom Ogilvy

"kuch68" wrote in message
...
I was just wondering if there was some code or function that exists to
convert hex to binary in vB. My program takes a 8 bytes of hex and

converts
them to binary populating each Bit in a column (64 columns). I need an

easy
way instead of using more columns to perform the HEX2BIN worksheet

function.

thanks
Josh




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Hex2Bin in VB

Kuch

try following (quick n dirty) functions.

note:
for Negative numbers the results are not similar to ATP's Dec2Bin..
results are leftpadded with 0s to multiples of 4


Option Explicit

Function IntToBin(iNumber As Integer) As String
IntToBin = HexToBin(Hex(iNumber))
End Function
Function LngToBin(lNumber As Long) As String
LngToBin = HexToBin(Hex(lNumber))
End Function

Private Function HexToBin(ByVal sHex As String) As String
Dim i&: Static col As Collection
If col Is Nothing Then
Set col = New Collection
col.Add "0000", "0"
col.Add "0001", "1"
col.Add "0010", "2"
col.Add "0011", "3"
col.Add "0100", "4"
col.Add "0101", "5"
col.Add "0110", "6"
col.Add "0111", "7"
col.Add "1000", "8"
col.Add "1001", "9"
col.Add "1010", "A"
col.Add "1011", "B"
col.Add "1100", "C"
col.Add "1101", "D"
col.Add "1110", "E"
col.Add "1111", "F"
End If
For i = Len(sHex) To 1 Step -1
HexToBin = col(Mid(sHex, i, 1)) & HexToBin
Next
End Function






--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


kuch68 wrote :

My mistake, what I am looking for is a conversion in my code instead
of populating columns. Something along the lines of

HexValueInput = Cells(i,j).value
BinaryRepresentation = Bin(HexValueInput)

Where Bin is a function to convert within my code. Can I use HEX2BIN
there like:

BinaryRepresentation = HEX2BIN(HexValueInput) ?

thanks again for your help
Josh




"Tom Ogilvy" wrote:

=Hex2bin("2b")

displays

101011

You have to have the analysis toolpak installed.

If that isn't the answer, then you need to restate your question in
a different way so we can understand it.

--
Regards,
Tom Ogilvy

"kuch68" wrote in message
...
I was just wondering if there was some code or function that
exists to convert hex to binary in vB. My program takes a 8 bytes
of hex and

converts
them to binary populating each Bit in a column (64 columns). I
need an

easy
way instead of using more columns to perform the HEX2BIN worksheet

function.

thanks
Josh




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
hex2bin - HEX2BIN KarenSue33 Excel Programming 2 February 21st 05 07:11 PM


All times are GMT +1. The time now is 02:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"