www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/ChangeTheEndiannessOfTheDataExample.m
%% Change the Endianness of the Data % By default, the |dsp.BinaryFileReader| System object(TM) uses the % endianness of the host machine. To change the endianness, such as when % the host machine that writes the data does not have the same endianness % as the host machine that reads the data, use the |swapbytes| function. %% % Write a numeric array into |myfile.dat| in big endian format. Read % the data using the |dsp.BinaryFileReader| object. The reader object % reads the data in little endian format. fid = fopen('myfile.dat','w','b'); fwrite(fid,[1 2 3 4 5 6 7 8],'double'); fclose(fid); reader = dsp.BinaryFileReader('myfile.dat','SamplesPerFrame',8); x = reader(); display(x); %% % |x| does not match the original data. Change the endianness of |x| using % the |swapbytes| function. y = swapbytes(x); display(y); %% % |y| matches the original data.