Questions tagged [binary-data]

Binary-data is information stored using a two character alphabet (typically written using 0 and 1)

Binary Data is information which is stored using a two character alphabet. For example, the number 42 could be stored as its base-2 representation: 101010.

In modern computers, almost all data is ultimately represented in binary form.

To be useful, the writer and reader of binary data must have a pre-agreed format (e.g. a file consisting of a 32-bit, two's compliment integer followed by three IEEE 754 floating point numbers).

The term is usually used to distinguish data stored in this way against data stored using a textual encoding. For example, the digits of 42 in base-10 (4 and 2) may be represented using ASCII as 00110100 and 00110010. Whether this is considered binary data or not depends on the task at hand; a chat client would consider messages as textual data, but the communication protocol it is built on may consider the same messages as arbitrary binary data.

1585 questions
13
votes
2 answers

How do I read binary data to a byte array in Javascript?

I want to read a binary file in JavaScript that would be gotten through XMLHttpRequest and be able to manipulate that data. From my researching I discovered this method of reading a binary file data into an array var xhr = new…
Zeeno
  • 2,671
  • 9
  • 37
  • 60
13
votes
5 answers

Insert image into xml file using c#

I've looked everywhere for the answer to this question but cant find anything so hoping you guys can help me on here. Basically I want to insert an image into an element in xml document that i have using c# I understand i have to turn it into bytes…
lilly1
  • 185
  • 1
  • 3
  • 8
13
votes
2 answers

Line reading chokes on 0x1A

I have the following file: abcde kwakwa <0x1A> line3 linllll Where <0x1A> represents a byte with the hex value of 0x1A. When attempting to read this file in Python as: for line in open('t.txt'): print line, It only reads the first two lines,…
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
11
votes
4 answers

How to translate from a hexdigest to a digest and vice-versa?

I want to store hashes as binary (64 bytes). But for any type of API (web service) I would want to pass them around as strings. hashlib.hexdigest() will give me a string, and hashlib.digest() will give me the binary. But if, for example, I read in…
esac
  • 24,099
  • 38
  • 122
  • 179
11
votes
1 answer

How can I convert a bytes::Bytes to a &str without making any copies?

I have a bytes::Bytes (in this case its the body of a request in actix-web) and another function that expects a string slice argument: foo: &str. What is the proper way to convert the bytes::Bytes to &str so that no copy is made? I've tried…
JoshAdel
  • 66,734
  • 27
  • 141
  • 140
11
votes
3 answers

Binary fields encoding/serialization format in a proprietary XML file (Roche LC480 .ixo file)

I recently received an example export file generated by the Roche LightCycler 480 instrument. It uses a proprietary XML format, for which I haven't found a specification yet. From such types of files, I would like to extract some information…
Alex
  • 13,024
  • 33
  • 62
11
votes
2 answers

Efficient binary I/O over a network

I'm trying to write a small Haskell program that talks a binary network protocol, and I'm having a surprising amount of difficulty. It seems clear that the binary data should be stored as ByteString. Question: Should I just hGet / hPut individual…
MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
11
votes
2 answers

How to Embed/Link binary data into a Windows module

So I have a Visual Studio 2008 project which has a large amount of binary data that it is currently referencing. I would like to package the binary data much like you can do with C# by adding it as a "resource" and compiling it as a DLL. Lets say…
CrimsonX
  • 9,048
  • 9
  • 41
  • 52
10
votes
2 answers

how to parse binary files in Clojure

What is the cleanest way to parse binary data in clojure? I need to be able to read/write equally cleanly to a file or a socket. something like: (read-data source-of-data) => { :index 42 , :block-size 4 , data-size: 31415, :data (1 2 3 4…
Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
10
votes
1 answer

Unknown 116-byte ECDSA private key format

iOS 13's CryptoKit framework provides a .rawRepresentation value for ECDSA public and private keys. I've been trying to reverse-engineer the rawRepresentation data type to convert between it and JWK. Judging by the 64-byte length of the public key…
Potassium Ion
  • 2,075
  • 1
  • 22
  • 39
10
votes
1 answer

Regex Binary Pattern Search in PHP

I am trying to find and replace binary values in strings: $str = '('.chr(0x00).chr(0x91).')' ; $str = preg_replace("/\x00\x09/",'-',$str) ; But I am getting "Warning: preg_replace(): Null byte in regex" error message. How to work on binary values…
Digerkam
  • 1,826
  • 4
  • 24
  • 39
10
votes
3 answers

Reading a CR2 (Raw Canon Image) header using Python

I'm trying to extract the date/time when a picture was taken from the CR2 (Canon format for raw pictures). I know the CR2 specification, and I know I can use Python struct module to extract pieces from a binary buffer. Briefly, the specification…
Escualo
  • 40,844
  • 23
  • 87
  • 135
10
votes
3 answers

Why are there binary safe AND binary unsafe functions in php?

Is there any reason for this behavior/implementation ?Example: $array = array("index_of_an_array" => "value"); class Foo { private $index_of_an_array; function __construct() {} } $foo = new Foo(); $array = (array)$foo; $key =…
user2917245
10
votes
4 answers

Prolog - handling binary data with DCGs

It seems to me one ought to be able to process binary data with DCGs on a list of bytes. To make it work generally, though, one has to use bitwise operations which means is/2 is involved, which means instantiation order is an issue, which may…
Daniel Lyons
  • 22,421
  • 2
  • 50
  • 77
10
votes
5 answers

How do computers translate everything to binary? When they see a binary code, how do they know if it represents a number or a word or an instruction?

I know how computers translate numbers to binary. But what I don't understand is that I've heard that computers translate everything (words, instructions, ...) to binary, not just numbers. How is this possible? Could you show me some examples? Like…