% Create scrip that convert float numbers to hexidecimal. % This file is useful for example if we need to load *.dat file to Code % Composer Studio. But this dat-file can understand only hexidecimal format % of number types such as int, long, float. % For start to work You must to set the input/output file name and path %and data type working with filename = 'dspInputSamples.dat'; outFileName = 'dspInputSamplesHEX.dat'; dataType = 'single'; %data of this type we read from input file with % "filename" name %descriptor of the file that must be opened %fid = fopen('my_file.dat', 'wb'); % открытие файла на запись inputFID = fopen( filename, 'rb'); if inputFID == -1 error('input File is not opened'); end %descriptor of teh output file outputFID = fopen(outFileName, 'wt'); if outputFID == -1 error('output File is not opend'); end %initialize the 1-D row vector. In this value we will save unput data rowVec = 0; %READ FROM FILE %samplesCnt - the number of elements read [rowVec, samplesCnt ] = fscanf( inputFID, '%f', inf ); %preallocate 1D column vector rowVecHEX = zeros( 1, samplesCnt, dataType); %CONVERTION rowVecHEX = num2hex( single( rowVec ) ); %WRITE TO FILE A = rowVecHEX'; for k = 1:samplesCnt lastSignificant_16_bits = A(5:8, k); mostSignificant_16_bits = A(1:4, k); fprintf( outputFID, '0x%c%c%c%cn', lastSignificant_16_bits ); fprintf( outputFID, '0x%c%c%c%cn', mostSignificant_16_bits ); end %display the row vector disp( rowVecHEX ); fclose( inputFID ); fclose( outputFID );
Нравится? Делимся информацией!
среда, 28 ноября 2012 г.
MatLAB script конвертация float из десятичной системы счисления в hex для Code Composer Studio
Подписаться на:
Комментарии к сообщению (Atom)
Комментариев нет:
Отправить комментарий