How to convert text file to asci code ?

조회 수: 22 (최근 30일)
Mostafa Salah
Mostafa Salah 2020년 5월 2일
댓글: Walter Roberson 2020년 5월 5일
I need to convert text file to binary ascii code to use in M-ASK modulation ? can any one help me ?

답변 (2개)

Vimal Rathod
Vimal Rathod 2020년 5월 5일
Hi,
Once you read the text data from your file, you can convert text to binary by using dec2bin function.
a = dec2bin("Some String");
The variable "a" will have the binary converted value.
For reading from text files you could refer to the following links of different read functions
Hope this helps.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 5월 5일
dec2bin() will not work on string objects. It will work on character vectors (but remember that characters can have more than 8 significant bits.)

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2020년 5월 5일
fid = fopen('FileNameGoesHere', 'r');
file_bytes = fread(fid, [1 inf], '*uint8');
fclose(fid);
%if needed
file_bits = reshape( (dec2bin(filebytes, 8) - '0').', 1, []);
file_bits would be a vector of 0 and 1 values.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by