How i can convert a text into binary and then split the binary form, finally convert each partition into ASCII code?
Mostrar comentarios más antiguos
Hello matlab community.
Sorry friends, I am a beginner with Matlab
I have a problem in this code, which is when i run this code for text file with small size , the time is very large. can any one help me to faster the running of this code?? is this code is true ?
fd=fopen('path\filename.txt'); % when the size of text file are 20 kilo bytes, it take about 30 minutes
format='%c';
Entered_Text = fscanf(fd,format);
Text_ascii = unicode2native(Entered_Text,'utf-8'); % Convert each character of a text into 8 bits ASCII code
for i = 1 : length(Text_ascii)
Binary_text{i} = dec2bin(Text_ascii(i),8); % Convert 8 bits ASCII code of a text into binary
out{1,i} = mat2cell(Binary_text{i},1,[2,2,2,2]); % Divide each Byte from (Binary_text) into four parts(each part two bits)
result = horzcat(out{:}); % Store the result of partitioned (Binary_text) into cell vector
Final_result = cellfun(@bin2dec, result); % Convert the result of each two bits into ASCII code
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!