Convert data to binary and ASCII format

If the variable
a=[3 2 1; 1 2 3; 2 3 1]
b=[1 2 3; 4 6 7; 5 3 5]
c=[a*b]
How to I save each variable as binary format and ASCII format?

1 comentario

sixwwwwww
sixwwwwww el 9 de Dic. de 2013
In how many bits you will like to represent a binary number?

Iniciar sesión para comentar.

Respuestas (1)

sixwwwwww
sixwwwwww el 9 de Dic. de 2013
Editada: sixwwwwww el 9 de Dic. de 2013
You can do it as follow:
a = [3 2 1; 1 2 3; 2 3 1];
dec2bin(a) % decimal to binary conversion
b = double(num2str(a)) % decimal to ASCII conversion

5 comentarios

Darren
Darren el 9 de Dic. de 2013
Thanks. But I just realized my coursework matrix have a negative integer in the matrix. And there's an error when I try to convert it to binary format using your method.
Eg
a=[-3 2 1; -1 2 3; 2 -3 1]
How do I convert to binary format in this kind of situation?? And 1 more thing, how do I save the converted format to disk at the end of the program?
Walter Roberson
Walter Roberson el 9 de Dic. de 2013
There are three different "standards" for converting negative integers. You need to decide which one you are going to use: sign bit, one's complement, or two's complement.
You can save the converted to disk using fprintf() or fwrite(); or you can use save(); or you can use one of the higher level routines such as csvwrite() or dlmwrite() or xlswrite().
Darren
Darren el 9 de Dic. de 2013
I get the saving to disk part but I don't understand sign bit, one's complement, or two's complement as I never heard or learn about them before.
Can you give me an example of how to convert a=[-3 2 1; -1 2 3; 2 -3 1] into binary format using signbit, one's complement or two's complement?
Walter Roberson
Walter Roberson el 9 de Dic. de 2013
Have you decided yet which representation you are going to use ?

Iniciar sesión para comentar.

Preguntada:

el 9 de Dic. de 2013

Comentada:

el 9 de Dic. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by