# I'm trying to convert the text into binary and then i want to make the 4 bits chunks.

2 visualizzazioni (ultimi 30 giorni)
Naveed il 30 Apr 2024
Commentato: Voss il 1 Mag 2024
But the problem is that how to make the total size at the output for example: 001010101010001110101110111010110101.
its mean that i have only 1 row and 36 columns.
but i can't do it.
please help me out!
clc;
close all;
clear alll;
% I'm trying to convert the Hello World into binary
message = ('Hello world');
A = dec2bin(message, 8); % Now to convert the charactors into 8 Bits using ASCI.
[r c]=size(A);
cc=struct([]);
A=convertCharsToStrings(A);
for j=1:1:r;
z=A(j,:);
cc=cat(2,cc,A(j,:));
end
disp(cc);
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

Voss il 30 Apr 2024
Modificato: Voss il 30 Apr 2024
Is this what you are going for?
message = 'Hello world';
A = dec2bin(message, 8);
cc = reshape(A.',1,[])
cc = '0100100001100101011011000110110001101111001000000111011101101111011100100110110001100100'
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Naveed il 1 Mag 2024
I want to covert the text into binary then make the 4 bits chunks and asign that chunks to any variable then check the size.
Voss il 1 Mag 2024
message = 'Hello world';
A = dec2bin(message, 8);
B = reshape(A.',4,[]).'
B = 22x4 char array
'0100' '1000' '0110' '0101' '0110' '1100' '0110' '1100' '0110' '1111' '0010' '0000' '0111' '0111' '0110' '1111' '0111' '0010' '0110' '1100' '0110' '0100'
size(B)
ans = 1x2
22 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Accedi per commentare.

Stephen23 il 30 Apr 2024
message = 'Hello world';
A = dec2bin(message, 8)
A = 11x8 char array
'01001000' '01100101' '01101100' '01101100' '01101111' '00100000' '01110111' '01101111' '01110010' '01101100' '01100100'
B = reshape(A.',1,[])
B = '0100100001100101011011000110110001101111001000000111011101101111011100100110110001100100'
##### 2 CommentiMostra NessunoNascondi Nessuno
Naveed il 1 Mag 2024
Now make the 4bits chunks and then check the size.
Stephen23 il 1 Mag 2024
"Now make the 4bits chunks and then check the size."
message = 'Hello world';
A = dec2bin(message, 8)
A = 11x8 char array
'01001000' '01100101' '01101100' '01101100' '01101111' '00100000' '01110111' '01101111' '01110010' '01101100' '01100100'
B = reshape(A.',1,[]);
C = reshape(B,4,[]).'
C = 22x4 char array
'0100' '1000' '0110' '0101' '0110' '1100' '0110' '1100' '0110' '1111' '0010' '0000' '0111' '0111' '0110' '1111' '0111' '0010' '0110' '1100' '0110' '0100'
size(C)
ans = 1x2
22 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Accedi per commentare.

### Categorie

Scopri di più su Numbers and Precision in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by