Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / June 2006

Tip: Looking for answers? Try searching our database.

Binary

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
javiernews - 27 May 2006 15:21 GMT
Hi,

Is it any buitl in function to convert any caracter to his equivalent in bits
(ceros & ones): ??

Example:

A = 01000001

Thnak you !
Douglas J. Steele - 27 May 2006 15:56 GMT
Not built in.

There is a built-in Hex function that will convert decimal values to Hex
values. You can then write your own function to convert the Hex values 0 to
F to the equivalent binary 0000 to 1111.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> Hi,
>
[quoted text clipped - 7 lines]
>
> Thnak you !
javiernews - 27 May 2006 16:56 GMT
Thank you for your prompt replay !
But

Ok for hexadecimal numbers,.........
but  I need something for binary numbers.

And I would need something similar to a  binary number like:

Msgbox ???? (01000001)    ' Returns A

or

MsgBox ???? ("A")                  ' Returns 01000001

Does this kind of function exits in Access ??

Thank You !
Douglas J. Steele - 27 May 2006 18:24 GMT
No, as I already said, there isn't such function built into Access.

However, it's fairly easy to write your own function.

You can use Asc to convert the symbol to decimal.

You can use Hex to convert the decimal representation to hex.

You can write a function to convert the hex to binary.

Something along the lines of:

Function CharBinary(Character As String) As String
Dim intLoop As Integer
Dim strInBinary As String
Dim strInHex As String

   strInBinary = vbNullString
   strInHex = Hex(Asc(Character))
   For intLoop = 1 To Len(strInHex)
       Select Case Mid(strInHex, intLoop, 1)
           Case "0"
               strInBinary = strInBinary & "0000"
           Case "1"
               strInBinary = strInBinary & "0001"
           Case "2"
               strInBinary = strInBinary & "0010"
           Case "3"
               strInBinary = strInBinary & "0011"
           Case "4"
               strInBinary = strInBinary & "0100"
           Case "5"
               strInBinary = strInBinary & "0101"
           Case "6"
               strInBinary = strInBinary & "0110"
           Case "7"
               strInBinary = strInBinary & "0111"
           Case "8"
               strInBinary = strInBinary & "1000"
           Case "9"
               strInBinary = strInBinary & "1001"
           Case "A"
               strInBinary = strInBinary & "1010"
           Case "B"
               strInBinary = strInBinary & "1011"
           Case "C"
               strInBinary = strInBinary & "1100"
           Case "D"
               strInBinary = strInBinary & "1101"
           Case "E"
               strInBinary = strInBinary & "1110"
           Case "F"
               strInBinary = strInBinary & "1111"
           Case Else
       End Select
   Next intLoop

   CharBinary = strInBinary

End Function

Now, CharBinary("A") will return "01000001"

I'll leave writing the inverse to you.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> Thank you for your prompt replay !
> But
[quoted text clipped - 13 lines]
>
> Thank You !
javiernews - 28 May 2006 02:37 GMT
Ok, Thanks a lot it was very helpfull.
Regards
Javier
Melanie O - 20 Jun 2006 21:11 GMT
Doug,

I am trying to convert a binary number to hex.  I used your code below,
switching the references between strInBinary and strInHex and adjusting the
Select Case statement values.  How do I change the following line to account
for a binary number since there is no built-in binary conversion function in
Access?

strInBinary = Hex(Asc(Character))  '(fifth line in function)

Thanks,
Melanie

> No, as I already said, there isn't such function built into Access.
>
[quoted text clipped - 78 lines]
> >
> > Thank You !
Tim Ferguson - 21 Jun 2006 18:52 GMT
=?Utf-8?B?TWVsYW5pZSBP?= <MelanieO@discussions.microsoft.com> wrote in
news:DFF71A0D-916C-4DCF-8C00-4057033578D0@microsoft.com:

> I am trying to convert a binary number to hex.

Public Function BinaryToLong(SomeBinary As String) As Long

 If Len(SomeBinary) = 0 Then
   BinaryToLong = 0
 
 Else
   BinaryToLong = _
     BinaryToLong(Left(SomeBinary, Len(SomeBinary) - 1)) * 2 + _
     Asc(Mid(SomeBinary, Len(SomeBinary), 1)) - Asc("0")
     
 End If
   
End Function

Hope that helps

Tim F
Melanie O - 21 Jun 2006 20:32 GMT
Tim,

Thanks for responding.  I tried out your function, and the result wasn't
quite what I expected.  One of the results was '3825' when I was expecting
something closer to '9AE7FECA1C3AA8419036EE8A89113363'.  Do I need to do
something else with the BinaryToLong result?

Thanks,
Melanie

> =?Utf-8?B?TWVsYW5pZSBP?= <MelanieO@discussions.microsoft.com> wrote in
> news:DFF71A0D-916C-4DCF-8C00-4057033578D0@microsoft.com:
[quoted text clipped - 18 lines]
>
> Tim F
Douglas J Steele - 22 Jun 2006 14:05 GMT
Tim's code converts binary to long integer (i.e.: base 10). You'll then need
to convert that to Hex.

What was the value you passed to it? There's no way on earth something that
would result in that long a Hex representation could be stored in a Long
Integer!

To convert binary to hex, make sure that the number of bits is a multiple of
4 (prepend zeroes until it is) then look at each nibble (group of 4 bits).
In other words, if you've got 1011100110, you'd add two 0s in front to get
001011100110, split that into 0010 1110 0110 then convert each nibble to
hex. 0010 = 2, 1110 = E, 0110 = 6, so you'd end up with 1011100110 equals
2E6.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Tim,
>
[quoted text clipped - 28 lines]
> >
> > Tim F
Melanie O - 22 Jun 2006 15:43 GMT
Doug,

Thanks for the clarification.  The problem is that I cannot see what value
is being passed to the function.  In SQL Server Enterprise Manager, the value
shows for every record as <binary>.  When I link the tables into Access, the
values show up as something like ਀皨ц䦿榁䲴◪ⶭ.  So I was looking for a function
to convert the supposedly binary numbers to hex.  Using the built-in Access
function Hex() only results in a #Error result.  Perhaps I need to figure
this out in SQL.  Thanks for the help.

Melanie

> Tim's code converts binary to long integer (i.e.: base 10). You'll then need
> to convert that to Hex.
[quoted text clipped - 42 lines]
> > >
> > > Tim F
Douglas J Steele - 22 Jun 2006 16:13 GMT
Binary data generally implies that the data is a Blob (it could be an image
or any other non-text format). Depending on what exactly you're trying to
do, look at the GetChunk method. See, for example,
http://support.microsoft.com/?kbid=194975

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Doug,
>
> Thanks for the clarification.  The problem is that I cannot see what value
> is being passed to the function.  In SQL Server Enterprise Manager, the value
> shows for every record as <binary>.  When I link the tables into Access, the
> values show up as something like ????????.  So I was looking for a
function
> to convert the supposedly binary numbers to hex.  Using the built-in Access
> function Hex() only results in a #Error result.  Perhaps I need to figure
[quoted text clipped - 48 lines]
> > > >
> > > > Tim F
Tim Ferguson - 22 Jun 2006 20:38 GMT
=?Utf-8?B?TWVsYW5pZSBP?= <MelanieO@discussions.microsoft.com> wrote in
news:BF11095C-A740-4602-9826-9D4EEC428126@microsoft.com:

>   In SQL Server Enterprise Manager, the value
> shows for every record as <binary>.

<vbg>

Tim F
Tim Ferguson - 28 May 2006 18:30 GMT
> Is it any buitl in function to convert any caracter to his equivalent
> in bits (ceros & ones): ??

debug.print LongToBinary(Asc("A"))
01000001

Public Function LongToBinary(SomeValue As Long) As String

 If SomeValue = 0 Then
   LongToBinary = "0"
   
 ElseIf (SomeValue And 1) Then
   LongToBinary = LongToBinary(SomeValue \ 2) & "1"
   
 Else
   LongToBinary = LongToBinary(SomeValue \ 2) & "0"
   
 End If
 
End Function

Hope that helps

Tim F
javiernews - 29 May 2006 07:23 GMT
Hi Tim,

Great !!  Very Good and very short code !!

THANK YOU !!!
Javier

>> Is it any buitl in function to convert any caracter to his equivalent
>> in bits (ceros & ones): ??
[quoted text clipped - 20 lines]
>
>Tim F
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.