Bifalgorithm post · Computer science one · Binary vs Text Files

When should data be stored in binary or text file format?

When should data be stored in binary or text file format? (Computer science one · Binary vs Text Files) — "As previously mentioned, files can be stored as pure…

Ideas in this flowchart

  • Elección entre almacenar datos como binario puro o como texto plano ASCII
  • La elección depende de la aplicación y de la naturaleza de los datos
  • El texto plano es necesario cuando los archivos deben ser legibles para las personas
  • En general, se debe preferir el formato binario
  • El formato binario normalmente requiere menos espacio
  • El formato binario es más eficiente de procesar
  • Ejemplo: almacenamiento de una colección de enteros
  • Cada entero ocupa 4 bytes en representación binaria
  • Como cadena, un entero requiere tantos bytes como dígitos tenga
  • El valor máximo requiere 10 caracteres ASCII, es decir, 10 bytes frente a 4 bytes en binario
  • Las cadenas de números necesitan un carácter delimitador adicional entre valores
  • En binario no se necesitan delimitadores porque cada bloque de 4 bytes representa un número
  • La diferencia puede ser aún mayor con otros tipos, como los números de coma flotante
Feed/

When should data be stored in binary or text file format?

No cover

Channel

Computer science one

1 page

"As previously mentioned, files can be stored as pure binary data or as plaintext (ASCII). Depending on our application and the nature of the data being written to files, the choice of which to use may be clear. If we want the data in our files to be human-readable, then we need to store them as plaintext. However, in general, we should prefer storing data in a binary format. The reason for this is that binary generally requires less space and is more efficient to process. Consider as an example, storing a collection of integers in a file. Each integer requires 4 bytes when represented in binary. However, when represented as a string, it requires as many bytes as there are digits in the number. For example, the maximum representable value of such an integer would be 2 31 − 1 = 2 , 147 , 483 , 647, requiring 10 ASCII characters and thus 10 bytes to represent, two and a half times as much memory as with the binary representation. Further, if a lot of numbers are stored, each number (as a string) would need to be delimited by yet another character. With a binary representation, no delimiter would be necessary as we would know that each 4 byte block represents a single number. This disparity can be even more stark with other types such as floating-point numbers."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.