A newbie question; I recieve data from the serial port using Comm recv. I then need to work with the recieved data at a Bit level - ie. be able to read each individual bit value in the recieved string.
Regards
John
Regards
John
'PBCC5.01 program FUNCTION PBMAIN() StringData$="ABCdef" FOR Char& = 1 TO LEN(StringData$) PRINT MID$(StringData$,Char&,1); Character? = CVBYT(StringData$,Char&) FOR WhichBit& = 7 TO 0 STEP -1 PRINT BIT(Character?,WhichBit&); NEXT PRINT NEXT WAITKEY$ END FUNCTION
#COMPILE EXE #DIM ALL FUNCTION showStringBits(stringIn AS STRING, BYVAL firstBit AS LONG, BYVAL lastBit AS LONG) AS STRING STATIC oneTime, ii, strLen AS LONG DIM bitTable(255) AS STATIC STRING * 8 LOCAL bitConvertStr AS STRING IF oneTime = 0 THEN FOR ii = 0 TO 255 'make an array one time only which shows binary version of all 256 bytes bitTable(ii) = BIN$(ii, 8) NEXT END IF strLen = LEN(stringIn) 'do a little range validity checking: IF firstBit > lastBit THEN SWAP firstBit, lastBit 'if first bit asked for is larger than last bit, swap them IF firstBit < 1 THEN firstBit = 1 IF lastBit < 1 THEN lastBit = 1 IF lastBit > 8 * strLen THEN lastBit = 8 * strLen bitConvertStr = SPACE$(8 * strLen) 'our initial string to hold 1's and 0's FOR ii = 0 TO strLen - 1 MID$(bitConvertStr, 8 * ii + 1) = bitTable(ASC(stringIn, ii + 1)) 'convert to 1's and 0's NEXT FUNCTION = MID$(bitConvertStr, firstBit, lastBit - firstBit + 1) 'choose bits to display END FUNCTION FUNCTION PBMAIN () AS LONG LOCAL strIn, bitStr AS STRING, firstBit AS LONG strIn = CHR$(51,52,53,54,55,56,57,58,59) bitStr = showStringBits(strIn, 1, 33) ? bitStr & $CRLF & "123456789012345678901234567890123" bitStr = showStringBits(strIn, 11, 11) ? bitStr bitStr = showStringBits(strIn, 12, 12) ? bitStr bitStr = showStringBits(strIn, 13, 13) ? bitStr bitStr = showStringBits(strIn, 14, 14) ? bitStr firstBit = 7 bitStr = showStringBits(strIn, 68, firstBit) ? STRING$(firstBit - 1, "$") & bitStr & $CRLF & "12345678901234567890123456789012345678901234567890123456789012345678" firstBit = 17 bitStr = showStringBits(strIn, 68, firstBit) ? STRING$(firstBit - 1, "$") & bitStr & $CRLF & "12345678901234567890123456789012345678901234567890123456789012345678" bitStr = showStringBits(strIn, 1, 1338) ? bitStr & $CRLF & "123456789012345678901234567890123456789012345678901234567890123456789012" END FUNCTION
sTest = "SomeBytes" ' Raw data Redim BitArray(Len(sTest)*8) ' BitArray() As String ("1"s and "0"'s) bp = StrPtr(sTest) ' bp as Byte Ptr For b = 0 To Len(sTest)-1 ' one byte at a time TempChar = Bin$(@bp[b],8) ' TempChar => 'Binary' string For c = 1 To 8 ' one bit at a time BitArray(i) = Mid$(TempChar, c, 1) ' build bit array Incr i Next Next For i = 3 To 6 ' e.g. group of bits sGroup += BitArray(i) Next ExampleRes? = Val("&B0"+sGroup)
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment