convert integer to bytes

조회 수: 61 (최근 30일)
VectraY
VectraY 2021년 12월 6일
댓글: VectraY 2021년 12월 6일
Is there a possibility to get the bytes representation of an integer? I want to use the bytes for the function native2unicode(bytes, 'UTF-8') to finisch the last few steps of the blowfish algorithm. Is there a proper way to do so? With dec2bin() I have not come far.

채택된 답변

James Tursa
James Tursa 2021년 12월 6일
편집: James Tursa 2021년 12월 6일
Depending on what you are doing downstream with this, you can use the typecast( ) function. E.g.,
bytes = typecast(my_integer,'uint8');
Note that MATLAB uses two's complement bit representation for integers, so both signed and unsigned integers will simply be re-interpreted as a series of unsigned bytes in the above.
  댓글 수: 1
VectraY
VectraY 2021년 12월 6일
thank you for your answer!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by