binary-data

R-How to generate random sample of a discrete random variables?

…衆ロ難τιáo~ 提交于 2019-12-03 23:25:39
This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 5 years ago . Learn more . In R, I want to generate a random sample of a discrete random variable: X , where: P(X=a)=P(X=-a)=1/2 . I have been searching for a function online, but there seems no direct function doing this. I think you are looking to generate samples of a Bernoulli random variable. A Bernoulli random variable is a special case of a binomial random variable. Therefore, you can try rbinom(N,1,p) . This will generate N samples, with value 1 with probability p , value 0 with

Python search and replace in binary file

百般思念 提交于 2019-12-03 23:24:36
I am trying to search and replace some of the text (eg 'Smith, John') in this pdf form file (header.fdf, I presumed this is treated as binary file): '%FDF-1.2\n%\xe2\xe3\xcf\xd3\n1 0 obj\n<</FDF<</Fields[<</V(M)/T(PatientSexLabel)>><</V(24-09-1956 53)/T(PatientDateOfBirth)>><</V(Fisher)/T(PatientLastNameLabel)>><</V(CNSL)/T(PatientConsultant)>><</V(28-01-2010 18:13)/T(PatientAdmission)>><</V(134 Field Street\\rBlackburn BB1 1BB)/T(PatientAddressLabel)>><</V(Smith, John)/T(PatientName)>><</V(24-09-1956)/T(PatientDobLabel)>><</V(0123456)/T(PatientRxr)>><</V(01234567891011)/T(PatientNhsLabel)>><<

Output binary data from CGI in Python 3

ⅰ亾dé卋堺 提交于 2019-12-03 16:16:32
This question is related to this one . I was having no problems while printing raw binary data from a CGI script in Python 2, for example: #!/usr/bin/env python2 import os if __name__ == '__main__': with open(os.path.abspath('test.png'), 'rb') as f: print "Content-Type: image/png\n" print f.read() Here are the relevant response headers: > GET /cgi-bin/plot_string2.py HTTP/1.1 > User-Agent: curl/7.32.0 > Host: 0.0.0.0:8888 > Accept: */* > * HTTP 1.0, assume close after body < HTTP/1.0 200 Script output follows < Server: SimpleHTTP/0.6 Python/3.3.2 < Date: Fri, 13 Sep 2013 16:21:25 GMT < Content

What data type is suitable to handle binary data in ActiveX method?

本秂侑毒 提交于 2019-12-03 16:06:31
I'm writing an ActiveX control for my friend, that should encapsulate encryption routines. It will be used from VB6 primarily. What data type should I choose for binary data like encryption key, initialization vector, input and output data so that it would be convenient for my friend to use it from VB6? I'm using Delphi 7 to write this ActiveX, if that matters. One choice is to use hexadecimal strings. What can be the other? kobik VB6 Binary data stored in Byte variables and arrays. Dim arrData() As Byte VB6 Application should pass that variable to your Delphi COM as OleVariant . Delphi COM

How to process large binary data in Clojure?

a 夏天 提交于 2019-12-03 14:46:28
How does one process large binary data files in Clojure? Let's assume data/files are about 50MB - small enough to be processed in memory (but not with a naive implementation). The following code correctly removes ^M from small files but it throws OutOfMemoryError for larger files (like 6MB): (defn read-bin-file [file] (to-byte-array (as-file file))) (defn remove-cr-from-file [file] (let [dirty-bytes (read-bin-file file) clean-bytes (filter #(not (= 13 %)) dirty-bytes) changed? (< (count clean-bytes) (alength dirty-bytes))] ; OutOfMemoryError (if changed? (write-bin-file file clean-bytes)))) ;

Framework for building structured binary data parsers?

浪子不回头ぞ 提交于 2019-12-03 12:23:34
I have some experience with Pragmatic-Programmer-type code generation: specifying a data structure in a platform-neutral format and writing templates for a code generator that consume these data structure files and produce code that pulls raw bytes into language-specific data structures, does scaling on the numeric data, prints out the data, etc. The nice pragmatic(TM) ideas are that (a) I can change data structures by modifying my specification file and regenerating the source (which is DRY and all that) and (b) I can add additional functions that can be generated for all of my structures

Meaning of a Common String In Executables?

我只是一个虾纸丫 提交于 2019-12-03 11:04:54
There appear to be some similar-looking long alphanumeric strings that commonly occur in Mach-O 64 bit executables and ELF 64-bit LSB executables among other symbols that are not alphanumeric: cat /bin/bash | grep -c "AWAVAUATSH" has 181 results, and cat /usr/bin/gzip | grep -c "AWAVAUATSH" has 9 results. What are these strings? Interesting question. Since I didn't know the answer, here are the steps I took to figure it out: Where in the file does the string occur? strings -otx /bin/gzip | grep AWAVAUATUSH 35e0 AWAVAUATUSH 69a0 AWAVAUATUSH 7920 AWAVAUATUSH 8900 AWAVAUATUSH 92a0 AWAVAUATUSH

C#/.NET - Custom Binary File Formats - Where to Start?

久未见 提交于 2019-12-03 10:04:13
问题 I need to be able to store some data in a custom binary file format. I've never designed my own file format before. It needs to be a friendly format for traveling between the C#, Java and Ruby/Perl/Python worlds. To start with the file will consist of records. A GUID field and a JSON/YAML/XML packet field. I'm not sure what to use as delimiters. A comma, tab or newline kind of thing seems too fragile. What does Excel do? or the pre-XML OpenOffice formats? Should you use ASCII chars 0 or 1.

How to extract hardcoded strings from a binary in Mac?

[亡魂溺海] 提交于 2019-12-03 09:08:21
问题 Is there API available in any language that can run on a Mac (Perl/Python/Cocoa/etc) or command line tools you can use to load a binary (app/bundle/framework/etc) and extract the hard-coded strings used in the code? The reason behind is we want to check if there are any hard-coded paths in our compiled binary. 回答1: Yes, you can just use the strings command line tool: $ man strings NAME strings - find the printable strings in a object, or other binary, file SYNOPSIS strings [ - ] [ -a ] [ -o ]

OpenCV binary adaptive threshold OCR

南笙酒味 提交于 2019-12-03 09:00:57
I need to convert some images to binary for OCR. Here are the functions I am using: Mat binarize(Mat & Img, Mat& res, float blocksize, bool inverse) { Img.convertTo(Img,CV_32FC1,1.0/255.0); CalcBlockMeanVariance(Img,res, blocksize, inverse); res=1.0-res; res=Img+res; if (inverse) { cv::threshold(res,res,0.85,1,cv::THRESH_BINARY_INV); } else { cv::threshold(res,res,0.85,1,cv::THRESH_BINARY); } cv::resize(res,res,cv::Size(res.cols/2,res.rows/2)); return res; } Where CalcBlockMeanVariance : void CalcBlockMeanVariance(Mat& Img,Mat& Res,float blockSide, bool inverse) //21 blockSide - the parameter