i need a bit stuffing example
i need a bit stuffing example
In what context?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
i want to simulate bit stuffing in frames
the flag is "01111110"
and i must do bit stuffing after the 5th bit
then un-stuffing it in the reciver
So we are talking HDLC comms, yes?
The problem with bitstuffing in C is that the language is not "bit oriented". It makes life quite difficult.
I take it this is an assignment of some sort, so you really should post your code first, then we can help you "improve it".
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
the code attached
please check the stuffing and the unstuffing function
Does this code work for you? I don't see anything directly wrong, but I can't say for sure if it works for all cases or not.
is the same asCode:pow(double(2),((max-1)-t))
The latter doesn't use "math.h" and is much quicker.Code:1 << ((max - 1)-t)
Did you mean 2048? If you use constants, it would be much easier to avoid typos like this [not that it REALLY makes any difference in this case - but still].Code:int data[2084];
Use:Code:dataCount=dataCount-2;
I just tried your code, typing in a few ~ characters [which is 01111110 in binary], and it didn't produce the same output as I input. It is hard to produce sequences that have more than 5 consecutive bits, since most such characters are unreachable from a normal keyboard.Code:dataCount -= 2;
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
thanks for the effort
To turn your byte array into a bit array, try something like this
Code:void writeBit ( unsigned char *array, int bitPosition, unsigned char bit ) { int bytePos = bitPosition / 8; // or CHAR_BIT to be precise int bitPos = bitPosition % 8; unsigned char mask = ~(1 << bitPos); // 11110111 with the 0 in the right place bit <<= bitPos; // the bit we want to set, in the right place, eg 00001000 array[bytePos] &= mask; // clear existing bit value array[bytePos] |= bit; // set new bit value }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.