convert binary to hex

조회 수: 151 (최근 30일)
sami ullah
sami ullah 2020년 9월 28일
댓글: sami ullah 2020년 9월 28일
I have a binary 256 bit. i.e 1x 256 char.
I have to convert it to hex then to decimal.
How it will be done?
  댓글 수: 1
sami ullah
sami ullah 2020년 9월 28일
For example:
binary='1110001111001100111110010000001111010000000001111111100011110011001111100100000011110100000000011111111000111100110011111001000000111101000000000111111110001111001100111110010000001111010000000001111111100011110011001111100100000011110100000000011111000111';
How to convert above binary into Hex, then to decimal.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2020년 9월 28일
편집: Stephen23 2020년 9월 28일
>> B = '1110001111001100111110010000001111010000000001111111100011110011001111100100000011110100000000011111111000111100110011111001000000111101000000000111111110001111001100111110010000001111010000000001111111100011110011001111100100000011110100000000011111000111';
>> H = dec2hex(bin2dec(reshape(B,4,[]).')).' % exact
H = E3CCF903D007F8F33E40F401FE3CCF903D007F8F33E40F401FE3CCF903D007C7
>> D = hex2dec(H) % loss of precision due to conversion to floating point!
D = 1.0304e+77
  댓글 수: 3
Stephen23
Stephen23 2020년 9월 28일
Faster:
>> H = sprintf('%X',[8,4,2,1]*reshape(B-'0',4,[]))
H =
E3CCF903D007F8F33E40F401FE3CCF903D007F8F33E40F401FE3CCF903D007C7
sami ullah
sami ullah 2020년 9월 28일
thanks

댓글을 달려면 로그인하십시오.

추가 답변 (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