How to convert bitstream to packets and bitxor function
이전 댓글 표시
I have to convert a bit stream file such as name `BL.264` source file . Now I want to parse the file into packets with packet size is 50 bytes. After that, I want to implement bit XOR between first packet and second packet. To do it, I will use `fread` and `bitxor` functions. However, I have some issues:
- If size of file is not divisible by packet sizes, we must add some padding at the end of final packet, *Right?* Let see my implementation, is it correct?
- The bitxor supports xor bitwise that have limit length. In my case, packet size is 50 bytes, it is impossible to bitxor two packet. How to resolve that problem.
Let see my code. If have any problem, let me know
function packet=bitstream2packet(file,psize)
%%file='BL.264';
%%psize=50;
fid=fopen(file,'r');
bytelist=fread(fid,'*uint8')';
bitexpanded = dec2bin(bytelist(:), 8) - '0';
bitstream = reshape( bitexpanded.', [],1);
%%Add padding
remain=rem(size(bitstream,1),psize);
bitstream(end+psize-remain)=0;
packet = reshape( bitstream.', [],50);
xorPacket=bitxor(packet(1,:),packet(2,:))
fclose(fid);
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!