Byte information

Posted on 2006-03-28
Last Modified: 2010-04-23
Dear Sirs,

I have read a single byte from a serial port and the value is &H89

This byte contains two bits of information (the first four bits contain the first part the last four bits contain the other value)  How can I seperate these two pieces of data from this single byte?

Many thanks
Question by:watersidedesigns
    LVL 20

    Accepted Solution

    If the byte is stored in a string variable:

    dim strInput as String
    dim intInput as Integer
    dim intHigh as Integer
    dim intLow as Integer
    ' load strInput here
    intInput = Asc(txtIn.Text)
    intHigh = intInput \ 16        ' Upper 4 bits
    intLow = intInput And 15    ' Lower 4 bits

    Note the use of \ rather than / for division; you want integer division, dropping the remainder.
    LVL 20

    Expert Comment

    Grr, replace txtIn.Text with strInput. I was copying from my test code and forgot to adjust that. Sorry!

    Author Comment

    Hi ElrondCT,

    Thats most helpful - thanks.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now