| ??? 01/06/01 07:13 Read: times |
#7896 - RE: Serial port and basic |
Shifting bits in BASIC:
Mathematically you can accomplist a shift left binary by multiplying a number by 2. To shift a 0 in, multiply the last number by 2 and add 0 (the add is unnecessary). To shift a 1 in, multiply the last nubmer by 2 and add 1. If you want to shift bits in by character strings you might look up the word concatenate. Storing bits as characters is actually storing them as 8 bits (an ascii character). If you want to collect more information (ie bits) then collect them in a buffer in binary form, and when the buffer is full, dump them to your terminal and at that time, convert them from binary to a character basis. Remember that a byte's bit positions represent: Bit 7: 2^7 =128, Bit 6: 2^6 =64, Bit 5: 2^5 =32, Bit 4: 2^4 =16, Bit 3: 2^3 =8, Bit 2: 2^2 =4, Bit 1: 2^1 =2, Bit 0: 2^0 =1 Pseudocode to convert a byte to print characters: for i=7 to 0 step -1 { .if BYTE-2^i >= 0 { ..print 1 ..BYTE = BYTE-2^i } .else { ..print 0 } } Or something close to that. :) aka j |



