Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

EditText direction, multiline problem when convert a string into binary then binary into string

$
0
0
Hi,
I want to convert a string into binary, then convert that binary into string. Here is my code:

% --- push button Convert Text into Binary.
function pb_C2B_Callback(hObject, eventdata, handles)
    clc
    text_M = get(handles.edit_message, 'String');
    bin_M = dec2bin(text_M,8);
    set(handles.edit_message, 'String', bin_M);

% --- push button Convert Binary into Text.
function pb_C2T_Callback(hObject, eventdata, handles)
    clc
    bin_M = get(handles.edit_message, 'String')
    text_M = sprintf('%s', bin2dec( bin_M ))
    set(handles.edit_message, 'String',text_M)

It works well if the text is single-line. Exp:
"abcd" ->
01100001
01100010
01100011
01100100
-> "abcd"

But it gots problem if the text is multi-line. Exp:
"abc
234" ->
01100001 ....
-> "a2b3c4" instead of
"abc
234"

Help me, please.

Viewing all articles
Browse latest Browse all 19628

Trending Articles