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 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