I have this octave code
PLAINTXT = "ABC";
UNICODED = [];
BINARY_VALUE = [];
for i = PLAINTXT
UNICODED = [UNICODED, unicode2native(i, "ISO-8859-1")];
BINARY_VALUE = [BINARY_VALUE, dec2bin(UNICODED)]
%% stop
endfor
it takes the plain text "ABC" and convert it using ascii encoding system then converting it to binary but I need each to be in a separate set it worked for me when first time when I convert the plain text but it gives me the error "error: horizontal dimensions mismatch (1x7 vs 2x7)" and I don't know what's the problem.
I tried to do as in the code above and I also tried to create another for loop inside the existing on and run the line "BINARY_VALUE = [BINARY_VALUE, dec2bin(UNICODED)]" inside it but it still give me the same result
dec2bin(a)
for a scalar a
returns a string, and in Octave a string is a 1xN character array.
dec2bin(a)
for an array a
returns a nxN character array (n being the number of elements in a
).
Hence, in the second iteration when you arrived at BINARY_VALUE = [BINARY_VALUE, dec2bin(UNICODED)]
:
BINARYVALUE
was a 1x7 character array after the 1st iteration UNICODED
is a 1x2 uint8
array dec2bin(UNICODED)
is hence a 2x7 character array So you are indeed trying to append a 2x7 character array to a 1x7 character array, which is not possible. I'm not sure what you want at the end, but you could do:
PLAINTXT = "ABC";
UNICODED = [];
for i = PLAINTXT
UNICODED = [UNICODED, unicode2native(i, "ISO-8859-1")];
endfor
BINARY_VALUE = dec2bin(UNICODED);
Result:
>> UNICODED
UNICODED =
65 66 67
>> BINARY_VALUE
BINARY_VALUE =
1000001
1000010
1000011
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.