Searching \ for '[OT] Help Hex->bin conversion (pic=easy, VB=??)' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Help Hex->bin conversion (pic=easy, VB=??)'.

Exact match. Not showing close matches.
PICList Thread
'[OT] Help Hex->bin conversion (pic=easy, VB=??)'
2000\03\21@132106 by Lea

picon face
Hi All.
       I'm ending a project that uses 2 radio HDLC interfaces, they read
several devices (sensors and stuff like that) and report the changes over
the radio to the base station, programming for this was ok (ASM love it),
2 month of work :), but now, I have to program a GUI (in Visual Basic)
so I can easily display all the information collected by the radio
interfaces, and I'm facing a very DUMB problem, and I don't know how
to solve it , It will sound stupid but, I don't know how to convert
a 8 bit (2 ascii Char , Hexadecimal value) to Binary (8 Char ascii bin)

Ej: If a Have in a X variable the "F0" value, I need to get "11110000"

How can i do it under VB?, it is so easy in ASM that I cannot believe that
I can't do it in VB.

Thanks in advance.

see you, bye.
  Leandro J. Laporta (LU2AOQ)
  mail: spam_OUTlu2aoqTakeThisOuTspamyahoo.com
  wrk: Arg. Assoc. for Space Technology.
  ham: TCP/IP high speed group HSG


__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

2000\03\22@165337 by Mike Mansheim

flavicon
face
<snip>
to solve it , It will sound stupid but, I don't know how to convert
a 8 bit (2 ascii Char , Hexadecimal value) to Binary (8 Char ascii bin)

Ej: If a Have in a X variable the "F0" value, I need to get "11110000"

How can i do it under VB?, it is so easy in ASM that I cannot believe that
I can't do it in VB.
<snip>
I'm sure that more elegant ways to do this abound, but this works and it
shows the
basics of base conversion.

Take each digit in X and convert it to a 4 bit string (F = '1111', 0
= '0000'),
then put them together to make the 8 bit string.

First, X will be a string - access each character in the string with the
mid$ string
function:

    binary_string = ""
    For j = 1 To Len(X)      'this watches for single character; should
also trap
         hex_char = mid$(X,j,1)   ' for lengths > 2

Then hex_char needs to be converted to a number, using something like:

         number = Asc(hex_char) - 48              'Asc converts char to
ascii number
         if (number > 9) Then number = number - 7           'upper case
letters
         if (number > 15) Then number = number - 32    'lower case letters

Then run each resulting number through a base conversion routine to build
the 4 bit string:

         For i = 3 To 0 Step -1
              divisor = 2 ^ i
              digit = Int(number / divisor)
              number = number - (digit * divisor)
              ' "&" is string concatenation; Chr is the inverse of Asc
              binary_string = binary_string & Chr(digit + 48)
         Next i
    Next j

    'pad with leading '0000' if single digit input
    if (Len(X) = 1) Then binary_string = "0000" & binary_string

Hope this helps!

2000\03\22@173150 by jamesnewton

face picon face
Here is the source of the page at
techref.massmind.org/method/math/bindecbits.asp
which sort of does this in VBScript

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<TABLE BORDER=1>
<TR><TH>Decimal</TH><TH>Binary</TH>
<%
aryBin = split("000,001,010,011,100,101,110,111", ",")

intI = 60000
intD = 10000
while intI > 9
       strOct = Oct(intI)
       response.write "</TR><TR><TD ALIGN=RIGHT>" & intI & "</TD><TD ALIGN=RIGHT>"
       for intJ = 1 to len(strOct)
               response.write aryBin(cint(mid(strOct,intJ,1)))
               next
       strOct = Oct(intI-1)
       response.write "</TR><TR><TD ALIGN=RIGHT>" & intI - 1 & "</TD><TD
ALIGN=RIGHT>"
       for intJ = 1 to len(strOct)
               response.write aryBin(cint(mid(strOct,intJ,1)))
               next
       if intI > intD then
       else
               intD = intD / 10
               end if
       intI = intI - intD
       wend

%>
</TR></TABLE></BODY></HTML>

---
James Newton .....jamesnewtonKILLspamspam@spam@geocities.com 1-619-652-0593
http://techref.massmind.org NEW! FINALLY A REAL NAME!
Members can add private/public comments/pages ($0 TANSTAAFL web hosting)


{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...