비트 스터핑 (bit stuffing)으로 데이터 전송과 관련한 과제를 프로그래밍하고 있습니다. 비트 스터핑은 5 개의 동일한 비트가 전송 될 때 역방향 비트가 데이터 스트림에 추가됩니다 (예 : 5 "0", " 1 "이 추가되며 5"1 ","0 "이 추가됩니다). 원본 텍스트 문서에서 비트를 얻는 방법과이를 새로운 텍스트 문서에 쓰는 방법을 알고 있습니다. 그러나, 추가 반전 비트에 대한 내 프로그래밍 부분이 잘못 어떤 이유로, 여기 Java 용 비트 스터핑
내 코드static void addBitStuffing(Reader r, Writer w) { //Reader is an object class read the data from an original text document, Writer write the read data to a new text document
int length = 0;
for(; r.hasMoreData(); length++){
}
boolean [] feld = new boolean [length];
int i = 0;
while(r.hasMoreData()){ //hasMoreData check if there is more data in a data stream after the pointer, i.e. if there is none, it would have a value of "false"
boolean bit = r.getNextBit();
w.writeNextBit(bit);
feld[i] = bit;
i++;
if (i >= 4){
if ((feld [i] == true) && (feld[i-1] == true) && (feld [i-2] == true) && (feld [i-3] == true) && (feld [i-4] == true)){
w.writeNextBit(false);
}else{
if((feld [i] == false) && (feld[i-1] == false) && (feld [i-2] == false) && (feld [i-3] == false) && (feld [i-4] == false)){
w.writeNextBit(true);
}
}
}
}
}
마지막으로 동일한 비트를 얻으면'i' 만 증가시키는 것이 쉽지 않을까요? – usr2564301
나는 문제를 해결했다, 고마워! – Aabbccc