How to apply dec2bin on a string to get a single output?
2 views (last 30 days)
Show older comments
I want to convert decimal into binary .
Since my data is in string like
a = '56515219790691171413109057904011688695424810155802929973526481321309856242040'
I have tried dec2bin(a), but it gives output in different rows,
I need the following output
dec2bin(56515219790691171413109057904011688695424810155802929973526481321309856242040)
ans='111110011110010011110110001100010001101000000110101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
But I'm not getting the same output by dec2bin(a).
Furthermore, I have to convert all the rows in to binary by importing a .txt file. Any help is much appreciated.
Thanking in anticipation.
0 Comments
Accepted Answer
Arif Hoq
on 8 Mar 2022
Edited: Arif Hoq
on 8 Mar 2022
a = '56515219790691171413109057904011688695424810155802929973526481321309856242040';
a1=cell2mat(split(a,' '));
a2=str2double(a1);
% check=dec2bin(5,6)
out=dec2bin(a2)
writematrix(out,'sampletable.txt')
7 Comments
Arif Hoq
on 8 Mar 2022
stephen, you are right. i was in a hurry while coding. i just checked the result not the coding size. Thank you very much for the hints.
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!