Results 1 to 6 of 6

Thread: 7bit=1byte!!!.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 1999
    Posts
    22

    Post

    How do I read the 7bits of a byte using VB6.0.
    Thanks.
    Latha

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    There are 8 bits to every byte.

  3. #3
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    Rino is right there are 8 bits to every byte. Each bit is a zero or one. This is called binary code. Each binary string has eight zeros and/or ones. i.e.(01010101). Search for binary in the forums here various people have talked about it. There is mostly code on howto convert ASCii to Binary then back again. Also the binary code makes a value. Therefore chr$(0) is Binary(00000000).

    ------------------
    DiGiTaIErRoR
    VB, QBasic, Iptscrae, HTML
    Quote: There are no stupid questions, just stupid people.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 1999
    Posts
    22

    Post

    I think you have misunderstood my question. I am sorry about it. I know that there are 8 bits in a byte. I would like to read the first 7bits out of 8bits and leave the 8th bit.

    Thanks
    Latha

  5. #5
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    Hi,
    If you want the value of the first 7 bits of 8 bits, reading right to left, then if the value is greater than 127 subtract 128 (Bit 8) from the value. (Binary 10000000 = decimal 128). Just an fyi, If you discard the first bit,(Bit 1) the one to the right, you end up with all even numbers.
    Some serial data streams do use only 7 bits. These are for text transmissions only. If your trying to read something like this then you also need to know whether the data stream includes a parity bit and the number of stop bits. Normally these are stripped from the data before it is placed in RAM so you'll never get a byte value greater than 127. But if you read the actual input you might have to read 10 bits at a time. e.g. 7 data bits, 1 parity bit, and two stop bits.

    DiGiTaIErRoR is correct in that there are several examples in previous posts on binary conversions. Some go into great detail in explaining Binary vs Hexadecimal vs Decimal vs yadda yadda yadda.

    Al.


    ------------------
    A computer is a tool, not a toy.
    <A HREF="mailto:[email protected]
    [email protected]">[email protected]
    [email protected]</A>


  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Post

    I agree with Al Smith, It's a largish topic. if you are getting into it then go to the online help and read up on binary AND, OR and XOR. Then make some functions using these for flipping/reading bits.

    ie
    Sub SetBit(TheByte as Byte, TheBit as int)
    Code goes here to make the bit 'TheBit' in 'TheByte' equal to '1'
    End Sub

    Then make unsetBit, or setAll bits, ClearAllBits or swapBit or Return Bit x from a byte.

    Then chuck all these subs into a Public class and compile it as a DLL which you can reference.

    I went though all this writing a GIF encoder in VB.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width