MATLAB Answers

0

print leading and trailing zeros into text file

Asked by mia saam on 4 Nov 2017
Latest activity Commented on by Cedric Wannaz
on 4 Nov 2017
hi I have this hex values 0BA12CE0 that I want to print to a text file ,uses these commands to do that :
fileID1 = fopen('enct40.txt','wt');
fprintf(fileID1,'%s\n',cd1);
fclosef(fileID1);
but when I open the text file the leading and trailing zeros are disappear like this 'BA12CE' how can I print the results as they are without any missing values ?

  3 Comments

Could you confirm that in the above that cd1 is '0BA12CE0' ? Already in character format?
This works here on R2016a,Win7
cd1 = '0BA12CE0';
fileID1 = fopen('enct40.txt','wt');
fprintf(fileID1,'%s\n',cd1);
fclose(fileID1);
type enct40.txt
output
0BA12CE0
It's dec value=195112160 when I use dec2hex(195112160) the leading zero will disappear

Sign in to comment.

Tags

1 Answer

Answer by Cedric Wannaz
on 4 Nov 2017
 Accepted Answer

>> dec2hex(195112160, 8)
ans =
'0BA12CE0'

  2 Comments

Sign in to comment.