How do I read the 7bits of a byte using VB6.0.
Thanks.
Latha
Printable View
How do I read the 7bits of a byte using VB6.0.
Thanks.
Latha
There are 8 bits to every byte.
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.
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
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>
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.