binary-data

Reading-in a binary JPEG-Header (in Python)

被刻印的时光 ゝ 提交于 2019-12-25 18:42:30
问题 I would like to read in a JPEG-Header and analyze it. According to Wikipedia, the header consists of a sequences of markers. Each Marker starts with FF xx , where xx is a specific Marker-ID. So my idea, was to simply read in the image in binary format, and seek for the corresponding character-combinations in the binary stream. This should enable me to split the header in the corresponding marker-fields. For instance, this is, what I receive, when I read in the first 20 bytes of an image:

Initializing Julia type with many fields containing data from binary file

 ̄綄美尐妖づ 提交于 2019-12-25 03:24:44
问题 I have a type with many fields (think hundreds). The constructor system in Julia is fine for when I'm working with small types, but you can imagine how unwieldy this gets when I'm working with a massive object: type Bar a:Int32 b:Int32 c:Int32 d:Int32 e:Float32 f:Uint8 g:Int64 h:ASCIIString # ... end bar = Bar(1, 2, 3, 4, 5, 1.1, 64, 2147483648, "Wall of text", [hundreds more]) Now, I'm reading data from a binary file. The binary file follows a specification such that the first 4-byte value

Reading binary file bitwise in R

牧云@^-^@ 提交于 2019-12-24 15:26:02
问题 Since I am not a programmer I got stuck solving this probably trivial problem: I would like to extract numeric values from binary file (example.Lis) using R. First 256 bytes contain a header. I know the header structure therefore I was able to decode its content. For instance, according the format description, OLE DATE information is stored in bytes 8-15 as a double data type. To read this, I simply used following command: my.file = file("example.Lis", "rb") headall<-readBin(my.file, raw(), n

Outputting a Binary String to a Binary File in C++

耗尽温柔 提交于 2019-12-24 12:58:06
问题 Let's say I have a string that contains a binary like this one "0110110101011110110010010000010". Is there a easy way to output that string into a binary file so that the file contains 0110110101011110110010010000010? I understand that the computer writes one byte at a time but I am having trouble coming up with a way to write the contents of the string as a binary to a binary file. 回答1: Use a bitset: //Added extra leading zero to make 32-bit. std::bitset<32> b(

Python: binary string error simulation

孤者浪人 提交于 2019-12-24 07:59:11
问题 I am currently writing a test for validating some error-correcting code: inputData1 = "1001011011" inputData2 = "1001111011" fingerPrint1 = parityCheck.getParityFingerprint(inputData1) # Expected: fingerPrint1=0 fingerPrint2 = parityCheck.getParityFingerprint(inputData2) # Expected: fingerPrint2=1 if fingerPrint1 == fingerPrint2: print "Test failed: errorCorrectingAlgo1 failed to detect error" else: print "Test success: errorCorrectingAlgo1 successfully detected error" Is there a python class

Set binary data using setblob in mysql connector/c++ causes crash

自作多情 提交于 2019-12-24 07:07:07
问题 I tried to use setBlob() as follows: class DataBuf : public streambuf { public: DataBuf(char * d, size_t s) { setg(d, d, d + s); } }; char b[20]; DataBuf buffer((char*)b, 20); istream stream(&buffer); PreparedStatement* s = con->PrepareStatement("insert into mytable (mybin) values (?)"); s->setBlob(1, &stream); int rows = s->executeUpdate(); This crashes at executeUpdate(). What am I doing wrong? 回答1: Are you sure that it isn't crashing on: s->setBlob(1, &stream); Check the debugger to make

put jpg data from xmlhttprequest into <img /> tag

时光怂恿深爱的人放手 提交于 2019-12-24 00:50:20
问题 here is some part of my code xmlhttp.open("GET", theUrl, true); document.imglive.innerHTML = '<img src="data:image/jpeg,' + xmlhttp.responseText + '"/>'; that don´t seem to work. i also tried document.imglive.src= xmlhttp.responseText; that neither worked I checked some of the asked questions here but none of the answers where helping at this porblem. 回答1: Use base64 for these things. In modern browsers there's this btoa native function that may help you: document.imglive.innerHTML = "<img

How to display binary data from curl in php

久未见 提交于 2019-12-23 11:55:21
问题 I'm writing simple php proxy and I have trouble displaying png file, the output is and it should be: The images are opened in Notepad++. My php curl code look like this: $ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $ua); curl_setopt($ch, CURLOPT_HEADER_OUT, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,

python unhexlify not working as expected

旧街凉风 提交于 2019-12-23 04:15:10
问题 Whenever a program opens a file it sees the file as binary data. It translates it to a higher interpretive language i.e. octal, hex, ascii , etc. In this case it displays hexadecimal in the LH pane and ansi (windows 7 so it should be CP1252) in the RH pane. The 3 pictures below illustrate the original view, then the desired alteration, and the 3rd is the actual change made by the code: with open(tar,'rb') as f: data = binascii.hexlify(f.read(160)) if old in data: print 'found!' data = data

How send data (TCP) in binary frame format

谁都会走 提交于 2019-12-22 11:33:26
问题 I need to stream data to a TCP-server and havnt done it before. The data should be in binary frame format. I googled and found this tutorial which I think describes what I need to do: http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient(v=vs.71).aspx But I dont know how to create the data in the format needed so I can send it in the correct way. It should be in this format: Field|Offset| Type | size(octets) id | 0 |unsign int| 1 name | 1 |Byte Array| 40 grade| 41 |sign float|