A simple string to Hexadecimal value

49 ビュー (過去 30 日間)
sai charan bandi
sai charan bandi 2015 年 6 月 18 日
コメント済み: sai charan bandi 2015 年 6 月 18 日
Hi everyone I am struggling with a simple problem. I want to convert simple string 'hello' to its hexvalue (68656c6c6f). I can use dec2hex converter, but I am getting a matrix
>> dec2hex('hello')
ans =
68
65
6C
6C
6F
I tried using mat2str command which produces ['68';'65';'6C';'6C';'6F']
but I want to finally produce a simple string '68656c6c6f', when I give input as 'hello' string.
Is it possible to do that in matlab??

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 18 日
編集済み: Azzi Abdelmalek 2015 年 6 月 18 日
a=dec2hex('hello');
out=reshape(a,1,[])
  2 件のコメント
sai charan bandi
sai charan bandi 2015 年 6 月 18 日
Thanks but I am getting '6666685CCF',instead of '68656c6c6f'
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 18 日
Ok, then use
reshape(a',1,[])

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

その他の回答 (1 件)

Stephen23
Stephen23 2015 年 6 月 18 日
編集済み: Stephen23 2015 年 6 月 18 日
Here are three easy methods, using sprintf is the fastest:
>> sprintf('%X','hello')
ans =
68656C6C6F
>> num2str(+'hello','%X')
ans =
68656C6C6F
>> reshape(dec2hex('hello')',1,[])
ans =
68656C6C6F
  1 件のコメント
sai charan bandi
sai charan bandi 2015 年 6 月 18 日
Thank You!

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

カテゴリ

Help Center および File ExchangeActiveX についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by