convert integer to bytes

101 vues (au cours des 30 derniers jours)
VectraY
VectraY le 6 Déc 2021
Commenté : VectraY le 6 Déc 2021
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.

Réponse acceptée

James Tursa
James Tursa le 6 Déc 2021
Modifié(e) : James Tursa le 6 Déc 2021
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 commentaire
VectraY
VectraY le 6 Déc 2021
thank you for your answer!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by