hex2dec return error

11 ビュー (過去 30 日間)
Jimmy Zhao
Jimmy Zhao 2020 年 6 月 2 日
編集済み: James Tursa 2020 年 6 月 3 日
>> hex2dec(238a)
hex2dec(238a)
Error: Invalid expression. Check for missing multiplication operator, missing or unbalanced
delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

回答 (2 件)

David Hill
David Hill 2020 年 6 月 2 日
hex2dec('238a');

Steven Lord
Steven Lord 2020 年 6 月 2 日
Since you're using release R2019b you can directly enter hex and binary numbers.
>> x = 0x238a
x =
uint16
9098
See the Release Notes for more information.
  2 件のコメント
Jimmy Zhao
Jimmy Zhao 2020 年 6 月 2 日
Actually, I want to read form a file with hex data and plot to them. I also want to check if they are negative numbers (> 0x7FFFFFFF). COnvert them to a negative number is it is. which funcation that I can use?
Thanks,
Jimmy
James Tursa
James Tursa 2020 年 6 月 3 日
編集済み: James Tursa 2020 年 6 月 3 日
If you are reading a 2's complement hex pattern for a known sized integer, you can just use the simple test you proposed. You could of course typecast the result into a signed integer and then check the sign, but it will give you the same result as the simple test you proposed. If you actually need the value, then just:
u = the unsigned uint16 number
s = typecast(u,'int16'); % the signed int16 number with same bit pattern as u

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

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by