function [] = convert_to_binary()
clear all;
clc;
tic;
Dir=dir('E:\Binary\_to_java\_inData');
filename=strcat(Dir(3).folder,'\',Dir(3).name);%生成路径
file_id = fopen(filename, 'rb');
fid=fopen('E:\Binary\_to_java\_outData\outdata.txt','w+');
while(feof(file_id) == 0)
data = fread(file_id, 30 * 10^6);
data = uint8(data);
dataOut = dec2bin(data);
fprintf(fid,'%s',dataOut');
end
fclose('all');
t1 = toc;
disp(['生成二进制时间为',num2str(t1),'秒']);
tic;
fid = fopen('E:\Binary\_to_java\_outData\outdata.txt','rb');
filename2=strcat('E:\Binary\_to_java\_outData\',Dir(3).name);%生成含后缀的路径
file_id = fopen(filename2, 'wb');
while(feof(fid) == 0)
A = fread(fid, 30 * 10^7);
A = A - 48;
x = size(A, 1);
Areshape = reshape(A, 8, x/8)';%按照列填充
%bin2dec运行太慢,程序替换此函数 begin
for i=1:1:8
Areshape(:,i) = Areshape(:,i) * (2^(8-i));
end
Areshape = sum(Areshape, 2);%按行相加(1:按行,2:按列)
Areshape = uint8(Areshape);
%bin2dec运行太慢,程序替换此函数 end
fwrite(file_id,Areshape,'uint8');
end
fclose('all');
t2 = toc;
disp(['还原为源文件时间为',num2str(t2),'秒']);