Effacer les filtres
Effacer les filtres

binary to string

44 vues (au cours des 30 derniers jours)
Aseel H
Aseel H le 20 Fév 2012
Modifié(e) : Stephen23 le 29 Avr 2015
if i want convert binary to text:as s = ('101011101011010101011010'); then i want convert eaceh 8bit to character when use function bin2str(s); give error: "can not convert more than 52 bit" it consider "s" one character but i want for examble: S = '101011101011010101011010'; [a,b] =size(s) a=1 b=24; I want convert s to 3characters as output is==>'abc'

Réponses (2)

Andrei Bobrov
Andrei Bobrov le 20 Fév 2012
a = reshape(s-'0',[],3)'
out = sprintf('%d',(a*(2.^(size(a,2)-1:-1:0).'))')
OR
a = reshape(s,[],3)'
out = sprintf('%d',bin2dec(a)')

Image Analyst
Image Analyst le 20 Fév 2012
How about this:
S = '101011101011010101011010'
S = reshape(S, length(S)/8, 8)
decimalValues = bin2dec(S)
In the command window:
S =
101011101011010101011010
S =
10100100
01011011
11110110
decimalValues =
164
91
246
  2 commentaires
user06
user06 le 29 Avr 2015
ok this is fine .. it is giving the decimal values. now what should i do to get string by these bits?
Stephen23
Stephen23 le 29 Avr 2015
Modifié(e) : Stephen23 le 29 Avr 2015
@Anamika jain: This will help you:

Connectez-vous pour commenter.

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by