ASCII to Hexadecimal with "x" in it: example A2--> 0x410x32 (help pleas)

4 ビュー (過去 30 日間)
Stan sdsd
Stan sdsd 2013 年 1 月 25 日
My question is : is it possible to transform ascii code into hexadecimal with the forme "Ox" before. For instance A2 become in Hexa, 0x410x32. But with matlab, if I use dec2hex I obtain a matrix. Same with the commande "double". Have you any idea to transform the ascii code into the way I want ? Does your solution can be included in a fprintf command ? Best regards Stanislas Achard
  1 件のコメント
Cedric
Cedric 2013 年 1 月 25 日
編集済み: Cedric 2013 年 1 月 25 日
So you want the string '0x410x32', starting from the string 'A2' (or any other string)? If so, do you want that for any length of string or just 2 characters ones?

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

採用された回答

Cedric
Cedric 2013 年 1 月 25 日
I would just go for a variant of:
>> str = 'A2A2AA22' ;
>> strhex = sprintf('0x%X', str)
strhex =
0x410x320x410x320x410x410x320x32
  3 件のコメント
Jan
Jan 2013 年 2 月 6 日
@Stan: This sounds like a task for SSCANF.
Stan sdsd
Stan sdsd 2013 年 2 月 6 日
I found a solution with sscanf char(sscanf(String,'%2X').')

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

その他の回答 (0 件)

カテゴリ

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