Want to get only characters after using bin2dec.

I'm first trying to change characters to binary using dec2bin. Have reshaped it to form a single row array and performed some actions which resulted in the shuffling of bits. Then I'm getting a data set in binary which after reshaping and using char(bin2dec) gives character array.
Problem : The obtained array consists of many blank spaces, which when copied to word sometimes shows special symbols. Is it possible to get a resultant array of only characters?

2 Commenti

share some code or error plz
Amrita  K
Amrita K il 14 Apr 2016
Modificato: Amrita K il 14 Apr 2016
AB=011111100110000001010111010010000111000000
m=numel(AB)
T=reshape(AB, (m/7),7)
CT=char(bin2dec(T))
After using the above code I'm getting CT=L@jnZ
But when m trying to reverse the whole step to get back AB, it's giving wrong results.
dec2bin('L@jnZ');
Reshape(ans, 1,35)
= 11111001100000110111100100011100000

Accedi per commentare.

 Risposta accettata

Walter Roberson
Walter Roberson il 14 Apr 2016
Modificato: Walter Roberson il 14 Apr 2016
Forward. You need the quotation marks.
AB='011111100110000001010111010010000111000000';
m=numel(AB);
T=reshape(AB, (m/7),7);
CT=char(bin2dec(T)).';
Now if you check more closely you will find that CT(1) is a blank. When you are testing your reverse you do not account for that.
AB_reconstructed = reshape(dec2bin(' L@jnZ'), 1, [])
isequal(AB, AB_reconstructed)

6 Commenti

Thank you Sir... It's working now. But I have noticed that it's not working if I copy the CT to word and then use it in the reconstruction code. Please let me know what I'm doing wrong.
It works for me
AB_reconstructed = reshape(dec2bin(CT), 1, [])
Amrita  K
Amrita K il 14 Apr 2016
Modificato: Amrita K il 14 Apr 2016
Sir it working if we directly copy CT, but it's not working if m storing CT to word document, then copying it from there.
I mean.. I'm trying to execute the codes separately at different locations.
How are you storing it to a word document and how are you retrieving it?
I'm jus simply doing copy paste.
Amrita  K
Amrita K il 14 Apr 2016
Modificato: Amrita K il 14 Apr 2016
Thank you Sir... It's perfectly working, it was jus compatibility issue. It's a great help.

Accedi per commentare.

Più risposte (1)

James Tursa
James Tursa il 13 Apr 2016
If you are shuffling the bits around, then you are likely getting resulting characters that are in the "non-printable" set ... i.e. those "special symbols" and other characters that don't even print. These are characters, they just aren't the usual text characters you see printed to the screen. They are a direct result of the algorithm you used to mix up the bits. So, no you can't get rid of them if you continue to use that algorithm. If you want normal text characters mapping into other normal text characters then you will need to use a different algorithm.

3 Commenti

Amrita  K
Amrita K il 13 Apr 2016
Modificato: Amrita K il 13 Apr 2016
Sir, but while trying to decrypt the obtained array it's giving wrong results.
The text when copied and used with bin2dec it's not showing the proper binary value as expected. Can you please help?
Since you're not sharing your code, all we can suggest for help is this link or this one.
I have now given the code above.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by