convert Hexadecimal to decimal in text file

5 ビュー (過去 30 日間)
Dung Tran
Dung Tran 2021 年 3 月 26 日
コメント済み: Dung Tran 2021 年 3 月 30 日
Hi everyone,
I have a text file with thousand of rows and 8 column, below is some examples of the contents:
00baf 00b4d 00bee 00af7 00bae 00bab 000c8 00c03
00bba 00b2c 00bf5 00b0d 00bbd 00bc47 00c1b 00bfc
00bb5 00b1d 00c07 00b30 00bd0 00be77 00c39 00c04
I want to convert these hexadecimal to decimal value for the whole text file, can someone help me with this. Thank you very much.

採用された回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 3 月 30 日
Use reshape():
reshape(DECd, 4, 6) % Because your converted data is 24 - by -1
Good luck
  2 件のコメント
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 3 月 30 日
% if you'd like to make 8 column of data, then
reshape(DECd, 3, 8) % Because your converted data is 24 - by -1
Dung Tran
Dung Tran 2021 年 3 月 30 日
nice, that works really GOOD. Thank you Mr Sulaymon. Have a good Monday!

サインインしてコメントする。

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 3 月 26 日
Here is the one of the easy solutions:
FN = 'HD.txt'; % File name
% Open the data file to process:
ID = fopen(FN);
% Scan the file:
data = textscan(ID, '%s'); % NB: All read data is put into a cell array
% Convert the imported cell array data into one
data = data{1};
% Convert Hexidecimal data into Decimal data
DECd = hex2dec(data);
fclose(ID);
Good luck
  1 件のコメント
Dung Tran
Dung Tran 2021 年 3 月 29 日
編集済み: Dung Tran 2021 年 3 月 29 日
Thank you very much, it works for Hex to dec, but the result is only in 1 column, do you know how to modify it into 8 column value ? like example below:
13311 13349 11381 18318 13183 13131
13143 13123 54453 12313 23423 13122
so on...
As your example, you put read data into a cell array. How can I put read data into 8 cell column array ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by