FAQ Database Discussion Community


binary search C

c,arrays,search,binary
Here's the signature of the binary search function: void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); I don't understand why we're sending a void* as the array pointer, instead of void**, since as far as I know, if i'm looking...

Write binary string in binary file Python 3.4

file,python-3.x,binary
I tried to write binary data in string to binary file. My string contains only 0 and 1. I tried to do it in this way file = open('file.bin','wb') d = pack(str(len(code))+'s', bytes(code, 'UTF-8')) file.write(d) But i have only txt file. And no one HEX redactor see it correctly. What...

Casting a bitset to unsigned char, and vice versa

c++,casting,binary,bitset
Working with unsigned char arrays, representing bits. I came across the following. On MSVC 2013 casting an std::bitset<8> to a char, and back. Seems to be a valid thing to do. However in the C++11 ISO standard. I wasn't able to find a reference of this being valid. From what...

Reading text file and dealing with numbers

matlab,for-loop,text,binary
I'm attempting to count the number of letters in a text file, but unfortunately I keep getting stuck if numbers are involved. So far I have been able to deal with letters and symbols, but unfortunately the ischar function doesn't help me when it comes to numbers. function ok =...

Benefits of storing hex in DB over file

php,mysql,sql-server,binary,hex
I've been tasked with migrating an in-house application from ASP with a MSSQL backend to PHP with MySQL. The application allows users to upload and download files, searching the content therein etc... After scoping out the current application, I've discovered that the previous developer stored the hex values of the...

Compression of char size integer by removing leading zeroes

c,binary,compression,decompression
I compressed a char array by removing leading zeros from integer data and packed them tightly (without leaving spaces bit-wise). I wish to decompress it to get my original data back. The data is 8-bit and can have any number of zeros ranging from 0 to 8. I cannot exceed...

How is the manipulation is done on bit level?

c++,binary,logic
Assume that the size of char is 1 byte and negatives are stored in 2's complement form #include<stdio.h> int main() { char c = 125; c = c+10; printf("%d", c); return 0; } How can be the answer is -121?...

Python: How to convert array of 4 digits to a larger number, bitwise?

python,binary,python-2.x
Let's say I have the array = [1,2,3,4] What I want is NOT to convert to the number 1234; but to take the bits of 1, 2, 3 and 4, concatenate them and convert back to a number. In other words, I would have to perhaps convert each number/digit to...

Dividing an image into two non-rectangular non-square sub-image in matlab

image,matlab,matrix,binary,divide
Assume that I have an image like this: http://www.mathworks.com/help/releases/R2015a/examples/images/BasicImageImportProcessingAndExportExample_03.png (It is original image in matlab pout.tif) And help image (binary mask) like this: http://upload7.ir/uploads//df17be22203e3099ba0d86e7cb203477bc909244.jpg (With the same size of the original image) I wrote this simple code for dividing the original image into two images: I=imread('pout.tif'); figure,imshow(I),title('original image') Ih=imread('helpPic.jpg'); Ih=rgb2gray(Ih);...

convert negative decimal to binary using 8 bits

binary
(Not sure if I am allow to ask a question like this but will delete if asked) Convert -25 into binary representation using 8 bits and 2's compliment format to represent a negative number. So far I got 11001 I tried to google methods but I am not sure how...

PHP - Set first array's values to second array's iterations

php,arrays,algorithm,binary
I'm trying to make one array set to the iterations of another array. I'm working on a hash algorithm that takes in a user value of the order they want the array. It takes their code and breaks it down into 40 blocks of binary to be converted into hexadecimal....

haskell: binary calculator recursion and return values?

haskell,recursion,binary,calculator
I wanted to change decimal numbers into binary numbers per recursion and if else! binary2 x = if x > 0 then binary x else 999 binary x = if x `mod` 2 > 0 then 1 && binary2 (x/2) else 0 && binary2 (x/2) well returning 0 or 1...

How can I receive to socket input as hexadecimal?

java,android,sockets,http,binary
I sent a GET message with socket. And I received response message as string. But I want to receive as hexadecimal. But I didn't accomplish. This is my code block as string. Can you help me ? dos = new DataOutputStream(socket.getOutputStream()); dis = new BufferedReader(new InputStreamReader(socket.getInputStream())); dos.write(requestMessage.getBytes()); String data =...

Matlab identity shift matrix

matlab,matrix,binary
Is there any inline command to generate shifted identity matrix in MATLAB? A=[ ... 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 1, 0,...

What is the point of writing your code with hexadecimal notation for numbers?

c++,binary,hex
I was just reading a programming book the other day which talked about writing better code. I got to a section which described how to take any binary number and convert it to hexadecimal notation. I'm sort of new to programming and I was wondering what the advantage was of...

Put Hex Into .bin File

binary,hex
How would you stick a string of hexcode into a .bin file? Like this, \x45\x67\x89 for example. I've seen the long examples where you use bash to strip it then add it to the .bin, but there must be a quicker and simpler way? Also, I am not too familiar...

Cplex constraint for 2 dimensional binary decision variables

math,model,binary,constraints,cplex
I need to solve a problem where my decision variables are binary and are a 2 dimensional matrix, in Cplex y[p][q], p and q both have the same range papers=1..78. I need to incorporate a constraint that restricts the sum of both a row and column to be smaller or...

Regex to match binary numbers with more than two set bits

regex,binary
If I have a number consisting only of 1's and 0's and I need to create a regular expression that will match only if said number contains more than two instances of the digit 1. Some examples: 1000000010001 0001100000000 1000110010000 0000001000000 0100010000000 I'd need my expression to correctly match the...

python addition 2 digit number

python,binary
I'm studying algorithms. The exercise consist in put a number of 2 digits (between 10 and 99) and then do the addition of the two digits. I made it in python and it works, but my teacher said that there's another way to do it without the conversions that i'm...

git: comparing binary files

git,binary
I need some help, how does git handle a binary file for pushing and pulling? Since I have 2 binary files, and I do not want to overwrite them. I want to get their differences. Is this possible? How can it be?

C# Building a Integer value with Binary operations from “Bits”

c#,binary,integer-arithmetic
I have a array of bytes that are actually binary values like this byte[] buf = new byte[] { 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; The binary representation is 1111 1110 (0xFF = 0, 0xF0= 1). The value of the integer or byte that needs to be...

Convert bitstring to tuple

binary,erlang
I'm trying to find out how to convert an Erlang bitstring to a tuple, but so far without any luck. What I want is to get from for example <<"{1,2}">> the tuple {1,2}....

Element-wise binary value concatenation of two matrices

matlab,matrix,binary,binary-matrix,binary-image
Element by element, I want to concatenate binary values from different matrices to one matrix. For example, |1 0 0| |0 1 0| |10 01 00| |0 1 1| |1 1 0| = |01 11 10| |1 0 1| |0 0 1| |10 00 11| How can this be done?...

PHP Replace binary file at hex address [closed]

php,replace,binary,hex,preg-replace
I want to modify a binary file server side of aprox. 700kb to change an url in it than save it. My first idea was to use bin to hex and preg_replace to replace url in binary. The adress for the url in binary is always the same, but i...

Unsigned Char is (null) after reading the binary file into the same

c,arrays,image,binary,unsigned
I have to open/read a file which is an ascii art file (image) and requires me to return the width and height of the image to the main routine and then requires me to pass the picture data back via a pointer. Here is the function prototype that I MUST...

Can someone explain Python struct unpacking?

python,parsing,struct,binary
I have a binary file made from C structs that I want to parse in Python. I know the exact format and layout of the binary but I am confused on how to use Python Struct unpacking to read this data. Would I have to traverse the whole binary unpacking...

Python Packing int32 but doesn't work?

python,c++,binary,packing
I have been at this all day and I can't seem to find a solution :( I have a header for a file I want to create (I'm parsing an obj file in Python to output into binary data to be loaded up in my C++ game engine). Here is...

Find location of a pattern of bits in a binary array in matlab

arrays,matlab,binary,pattern-matching
I have an array of binary data with long stretches of ones and zeros and I want to find the indices of when it changes. a = [ 1 1 1 1 1 0 0 0 0 0 0 1 1] I want to search for [1 0] and [0...

Dissecting a binary file in C

c,binary
I'm working on assignment in which I need to dissect a binary file retrieve the source address from the header data. I was able to get hex data from the file to write out as we were instructed but I can't make heads or tails of what I am looking...

How to convert binary into decimal using library?

c++,binary
I use this simple code to convert a decimal into binary : #include <iostream> #include <windows.h> #include <bitset> using namespace std; int main(int argc, char const *argv[]){ unsigned int n; cout << "# Decimal: "; cin >> n; cout << endl; bitset<16>binary(n); cout << endl << "# Binary: " <<...

Why don't integers “underflow” in PHP?

php,binary,signed
If I do this in PHP: echo (int)9223372036854775808; The output is -9223372036854775808, which makes perfect since since 9223372036854775807 in binary is: 0111 ... 1 i.e., 0 followed by 63 ones. And obviously 1 in binary is just 1, so when I add them I get 1000...0 (1 with 63 0s...

NumberFormatException while converting a *binary* string to a number

java,binary,integer,number-formatting
So I have this binary string (32 chars corresponding to 32 bits): String s = "11111111110000011101110111011000"; When I try to convert it to a number, it throws a NumberFormatException: Integer.parseInt(s,2); Could not figure out why. Any idea? The strange thing is if I replace the first bit in the string...

Binary to CSV record Converstion

python,csv,binary,data-conversion,hexdump
Hi FolksI have been working on a python module which will convert a binary string into a CSV record. A 3rd Party application does this usually, however I'm trying to build this logic into my code. The records before and after conversion are as follows: Hex String of the CSV...

How can I implement BCD in Fortran?

binary,fortran,bcd
Not sure if the title of my question makes sense, so bear with me. I'd like to find a system for representing single digit numbers with as few bits as possible. There is a method called "Densely packed decimal" (https://en.wikipedia.org/wiki/Densely_packed_decimal) which would be my ideal solution, but I wouldn't even...

Store 2 values in one variable

go,binary,bit-shift,bits
Is this Go code correct and portable, I need to store 2 counters (each call only one counter will be updated) in one variable to avoid locks in actual code where I am going to use single atomic.AddUint64() instead of locking whole struct. package main import "fmt" var long uint64...

Need help to work with characters longer than 2 or more bytes in Python

python,binary,byte,bits
I'm learning about bits and bytes in python by writing a small program that converts strings to binary and back to string again. Temporarily I only have a function that converts to binary. string = 'word' for c in word: convertToBinary(c) #Function that converts to binary Output: 01110111 01101111 01110010...

Write float array into a binary file c#

c#,matlab,file,binary,floating-point
I have a float array : float[] samples32array I need to convert it into a binary file so I can read it in matlab. Is there any way to do that?...

Printing vector in reverse order using range-based for loop

c++,c++11,for-loop,binary
I have this code that convert a decimal number into a binary one: #include <iostream> #include <windows.h> #include <vector> #include <algorithm> using namespace std; void space(){ cout << endl << endl << endl; } int main(int argc, char const *argv[]){ system("color 1F"); unsigned long int n, copy_n; vector<int> v; cout...

c++: exception error after closing console app

c++,binary,ifstream,ofstream
I am in the process of learning c++ and have a question regarding reading and writing objects to files. I created a class called Person. In my main file I created two instances of the Person class. I write instance one to a file called "person.dat" and later read it...

Differences between: INT 10H , INT 16H, INT 21H

assembly,binary,emulator,8086
Could anyone please explain to me the differences between: INT 10H , INT 16H, INT 21H in assembly language? When should we use any of them and for what? For example: in this simple code for printing "Hello, World!" Why did we use int 10h in the fourth line? Why...

fwrite() not working to write integer in binary file

c,file,binary,fwrite
Can someone tell my why won't this function work? I just can't get it... void writeRegister(FILE *arq, Book *L){ //writes in actual file position char c = '|'; int sizeRegWrite = reglen(L); //reglen() returns the size of Book fwrite(&sizeRegWrite, sizeof(int), 1, arq); fwrite(L->TITLE, sizeof(char), strlen(L->TITLE), arq); fwrite(&c, sizeof(char), 1, arq);...

Binary reader with arduino blinking 8 leds

binary,arduino,led
I´m trying to insert a binary raw sequence (01010100, 01101000, 01100001) into Arduino. I would like to make 8-led group blink in a loop, showing with light each 8-group binary sequence when: 0=light off and 1=light on. It´s possible to do this operation with Arduino-Uno?...

Can we open a binary file in C without fopen?

c,binary,fopen
In C programming, can we open a binary file without fopen() , only with open ? Because I need a file descriptor, not a filestream. Thank you...

Writing/reading binary bytes/ints/longs to/from file stream in C++

c++,io,binary,fstream,blitzmax
So I've only recently started to try C++ and I've already learned the basics. All I want to know is how can I write/read bytes/ints/longs to/from a file. First of all, I'd like to tell you why do I need it. Basically I want to read data from a file...

Need help adding with Twos Complement notation

binary
I'm having slight confusion over two's complement. I have reviewed What is “2's Complement”?. I'm trying to add -2 + -3 = -5. Here's my thought process: +2 = 0010 -2 = 1110 # in twos complement +3 = 0011 -3 = 1101 # in twos complement 1101 +1101 -----...

4 bytes to a Float in a swift gives an unexpectedly small result

swift,binary
I'm trying to reconstruct a float from a binary stream in Swift according to this answer. As far as I can tell, the bytes are correct, but the resulting float is not. func didReceive(data: NSData!) { var x:Float = 0 var bytes:[UInt8] = [UInt8](count: 4, repeatedValue: 0) data.getBytes(&bytes, range: NSMakeRange(0,...

Writing floats to a binary file in C++ | Equivalent of Java's DataOutputStream.writeFloat()

java,c++,file-io,binary
I'm porting some code from Java to C++ and need to write floats to a binary file. In Java I use DataOutputStream.writeFloat(). How do I do it in C++? I tried this method but it doesn't work: std::ofstream out; out.open(somePath, std::ios::out | std::ios::binary); float f = 0.5; out.write(reinterpret_cast<const char*>(&f), sizeof(float));...

Can someone help me explain this code that is converting decimal fractions into a binary?

python,while-loop,binary,floating-point,decimal
Can someone help me explain this code that is converting decimal fractions into a binary? Convert the decimal fractions into a binary form: x = float(raw_input('Enter a decimal number between 0 and 1: ')) p = 0 while ((2**p)*x)%1 != 0: print('Remainder = ' + str((2**p)*x - int((2**p)*x))) p +=...

Is there a preferred manner for sending data over a web socket connection?

c#,python,json,websocket,binary
Is there a 'correct' or preferred manner for sending data over a web socket connection? In my case, I am sending the information from a C# application to a python (tornado) web server, and I am simply sending a string consisting of several elements separated by commas. In python, I...

split single column to several columns of binary matrix

r,binary
I have a big dataset in R which several individuals listed in several rows in one column for one area. ID Elevation Year Individual.code 1 Area1 11.0 2009 AA 2 Area1 11.0 2009 AB 3 Area3 79.5 2009 AA 4 Area3 79.5 2009 AC 5 Area3 79.5 2009 AD 6...

How to print a binary number

python,python-2.7,binary
I am starting to work on a Vernam cipher in Python and apparently there is something I do not know about working with binary in Python, for exmple if I print 00011 in console it returns a 9. """Sistema de Cifrado Vernam""" #alfabeto alfabeto = {"a":00011,"b":11001,"c":01110,"d":01001,"e":00001,"f":01101,"g":11010,"h":10100,"i":00110,"j":01011,"k":01111,"l":10010,"m":11100, "n":01100,"o":11000,"q":10111,"r":01010,"s":00101,"t":10000,"u":00111,"v":11110,"w":10011,"x":11101,"y":10101,"z":10001, "<":01000,"=":00010,"fdown":11111,"fup":11011,"...

racket: maximum height of a binary tree

tree,binary,height,racket,distance
I'm trying to create a code in racket that will find the maximum distance in a binary search tree from the root to a leaf. I've seen this done in C++ but am having trouble translating it to racket. I've managed to calculate all the nodes in a tree, but...

How to convert binary to hex code digit-wise

c++,binary,hex
In C++ I've four binary numbers stored in four strings, let's say: string s1="1010", s2="1011", s3="0100", s4="0011"; OR directly stored as ints: int i1=10, i2=11, i3=4, i4=3;. I don't know which situation will lead to the better solution, that's why I wanted to clarify, that I can start with both....

Why bitshift when evaluating truth tables as binary numbers?

binary,truthtable
The last answer in this question shows that a binary truth table can be represented as a binary number: 0 0 0 | 1 0 0 1 | 1 0 1 0 | 0 0 1 1 | 0 1 0 0 | 1 1 0 1 | 0 1...

ObjectInputStream and Binary Data

java,binary,objectinputstream
I got problems loading my application up with a binary file. I am trying to read from the binary file and inject the data to some HashMaps/ArrayLists in my application. public void loadBinary(String filename) { InputStream input = getClass().getResourceAsStream(filename); try (ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(input))) { // TODO }...

How to convert string of binary values back to char

c++,arrays,string,binary,bitset
Example NOTE: that i am only concerned about letters. so bitset 000001 would be a or A. I have a string named s with the value "abc". I take each char of the string and convert it to binary value through the use of bitset. e.g bitset <6> b1 =...

Why can I view some Unix executable files in Mac OS X and not others?

git,bash,shell,unix,binary
I am on a Macbook Pro on Mac OS X 10.10 (Yosemite). When I go to /usr/bin, git is there as a unix executable file. When I open it up in Sublime Text, all I get is unreadable machine code. However, when I open up a different Unix executable file—in...

Real-time monitoring of intermittent binary data

linux,terminal,binary,buffer,monitoring
Context: monitor a low-volume, intermittent stream from a program When debugging some program, one sometimes have to monitor some output. When output is ascii, no problem, just run in terminal (the program itself, or nc if it uses a TCP or UDP interface, or cat /dev/somedevice, or socat ..., whatever)....

1MiB = 1024KiB = 2^10. Nonetheless, why not use just 1000 byte instead 1024 to calculate size? [closed]

memory,binary,size,cpu
1024 = 2 to the power 10. Computers use binary system where the base is 2 (0 and 1). Humans use decimal system where the base is 10. So if I have 1 byte which contains 8 bit in modern computers I can represent up to 256 different states, possibilities,...

How can i store 2 numbers in a 1 byte char?

c++,c,binary,fortran,bcd
I have the question of the title, but If not, how could I get away with using only 4 bits to represent an integer? EDIT really my question is how. I am aware that there are 1 byte data structures in a language like c, but how could I use...

I'm trying to make a Python procedure that converts binary numbers to decimal numbers

python,python-2.7,binary,procedure
I'm trying to create a procedure out of the following code in Python: print "Program for Binary to Decimal Conversion" dec = 0`enter code here` bin = 0 factor = 1; print "Enter Binary Number:", bin = input() while(bin > 0): if( (bin % 10) == 1): dec += factor...

Read a binary file using Numpy fromfile and a given offset

python,arrays,numpy,binary
I have a binary file which contains records of position of a plane. Each record look like: 0x00: Time, float32 0x04: X, float32 // X axis position 0x08: Y, float32 // Y axis position 0x0C: Elevation, float32 0x10: float32*4 = Quaternion (x,y,z axis and w scalar) 0x20: Distance, float32 (unused)...

Function that return average depth of a binary search tree

c,algorithm,tree,binary,binary-tree
I have the following binary tree structure, and I'd like to write a function that calculates and return the average depth of objects in a tree. Here is what I'm trying to do: calculate the total height of the tree divide total height/total nodes However, I'm getting nowhere, and would...

Error in binary String to Integer converter

java,string,algorithm,parsing,binary
I have binary String To Integer method implemented in my code. Problem is that I'm getting wrong last two digits of method output results, e.g.: SHOULD BE RESULT : 11111111100001001000101110000100 RESULT : 11111111100001001000101110000011 There is always problem with last two digits of result. Any help would be greatly appreciated. code:...

Arduino Uno - Incorrect/Scrambled Serial Data

binary,arduino,arduino-uno,eeprom
I have been struggling to write a very simple Arduino program that increments address pins to an EPROM and then reads in the data through other pins. When I was unable to do something as simple as increment an array of boolean values (the MSB on both values is almost...

C++ reading binary data to struct

c++,binary,alignment
I am currently reading a binary file that i know the structure of and i am trying to place into a struct but when i come to read off the binary file i am finding that when it prints out the struc individually it seems to come out right but...

2 bit right shift of a 32 bit unsinged integer with special conditions in assembly.

assembly,binary
I just had my "Langage de Programmation" exam, which was about knowledge and use of assembly code. One of the questions asked this and I was unsure what the answer should have been: Let N1 be an unsinged integer over 32 bits. Give the assembly code allowing to realise the...

Why these “exported” variables are double-defined?

c,binary,reverse-engineering,x86-64,elf
I am testing some 64-bit ELF binaries on x86/Linux. I compiled apache server using gcc, with its default configuration (optimization level O2 I guess). I stripped the httpd binary with strip command, and I use this command to check the exported variables inside the httpd ELF binary. For example, for...

create list of binary strings (Python)

python,list,binary
I have a directed Multigraph and would like to identify the nodes with a binary string representing the coordinates of each node. How can I build a list of these coordinates depending on the dimension of the multigraph? Also the order of the coordinates is relevant. The first number is...

Matlab: Binary Linear Programming

matlab,matrix,binary,integer,mathematical-optimization
I am trying to solve some equations on Matlab using Binary Integer Programming. I have 3 sets of equations: Ma.X=1 Mp.X<=1 Mr.X<=m* Where, Ma is a known matrix with size 5*12 X is unknown set with size 12*1 Also Mp is known matrix with size 5*12 and Mr is a...

Last two bits in a BitArray of length 4 are being ignored when converting to int

c#,binary,int,bit,bitarray
Consider the following BitArray: BitArray bitArray = new BitArray(new Boolean[] {true, true, false, false}); and in binary equals: 1100 Now I want to convert this to an int and have tried to use the methods described on this page: How i can convert BitArray to single int? However, both these...

How to use constant powers of 2 readable in c++?

c++,binary,coding-style,constants,code-readability
I need several integer constants with 2^n and 2^n - 1 in my GNU c++ code. What is a good practise to keep the code readable? The code uses decimal values at the moment 4294967296 and 65536 which is hard to debug in future. 2^12 is not implemented in standard...

Converting a binary string to an ascii string, the long way (No API Functions)

java,algorithm,binary,ascii
I had an interview recently and discovered that I'd forgotten some of the basics. I've been playing around again and have written a function that will take a binary string (there is no validation yet) and returns the ascii representation of said string. I'm looking for advice or tips on...

Converting an html page to binary format in python

python,html,mongodb,binary
Suppose I have these two lines: c=urllib2.urlopen(myUrl) html=c.read() I'm quite new to Python and am looking for a way to transform the HTML code stored in html in a binary array so I could easily store in my MongoDB without worrying about the encoding of the webpage I downloaded. Suggestions?...

Binary division - Highlighted an area of not understanding

math,binary
I have highlighted in green the area of which I don't understand. Can someone please explain to me where the 000 comes from? thanks :-) ...

Convert binary string to hex string and keep its leading zeros

python,string,binary,hex
May I know how to write a Python script to convert binary string to hexadecimal string and keep the leading zeros? For an example, I have binary string "0000000000001010" and would like to print it into "000A". I know i can use zfill() function, but the number of leading zeros...

Decimal to Binary Conversion Error

binary,decimal,void
How do you fix the following problem converting from decimal to binary? void tobinary(int bin) { string binary = Convert.ToInt32(bin, 2); } These are the errors: Error 2: Argument 2: cannot convert from 'int' to 'System.IFormatProvider' 42 Error 1: The best overloaded method match for 'System.Convert.ToInt32(object, System.IFormatProvider)' has some invalid...

Type safety and NEG instruction

c++,binary,opcode
I need to port this Assembly instruction: NEG eax so I did following: uint32_t a = 0x1234568; a = reinterpret_cast<uint32_t>(-a); since reinterpret_cast does what I want, meaning interpreting bytes directly without any kind of casting/conversions. Do I need reinterpret_cast for this purpose? Does this violate strict aliasing? If I do...

Convert Binary File To String In Perl

perl,binary,hex,ascii
Ok. I have spent the last 14 hours trying to figure this out. I have a binary file with the following contents - (much more, but this is truncated version). I wish to convert this to readable string format. ^@^P<9A>^@^@^A^@[email protected]^@^@^A^@[email protected]^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^F<9A>^@^@^@^@^@^@[email protected]]U:^@^M^@...

Implementing c binary division in o(1)

c,binary,division
I found this (slightly modified) code to implement division on unsigned numbers: #include <climits> #include <stdio.h> unsigned divide(unsigned dividend, unsigned divisor) { unsigned current = 1; unsigned answer=0; if ( divisor > dividend) return 0; if ( divisor == dividend) return 1; while (divisor <= dividend) { // this will...

Convert the Number to binary using IEEE 754 standard (32-bits)

binary,numbers,32-bit,ieee-754,ieee
I am trying to convert the number -11.25 to binary using IEEE 754 standard 32- bits. This is what i got so far: -11.25 = 1011.0100 1.0110100 * 2^3 3 + 127 = 130 = 1.0110100 * 2130 IEEE 754 standard = 1 10000010 1011010...0 I think that my answer...

Read From a Binary file With FileInputStream

java,file,binary
I'm starting to learn Java I/O. I have a binary File with Integer data in it and I'm trying to read from it using FileInputStream and showing the content of the file on the console. It seems I'm not making the right approach, keep getting -1 witch means end of...

Python struct.unpack binary file

python,struct,binary
I'm using struct.unpack to read the 11th byte of a file to the 21st byte which represents a field that is supposed to read 'SNA'. The field is 'populated as BCS-A where it is left justified and padded to the right boundary with BCS spaces'. Since the field is 10...

How to Convert Binary to Hex

binary,hex,byte,bits
So I have a binary number but there's only 11 bits. The number: 10111101110 I need to convert this to hexadecimal. I divide into three parts: 101 1110 1110 I know the last two parts are EE The part with three bits is catching me. If i add a zero...

Perl decimal and binary conversion with big numbers

perl,binary,type-conversion,decimal
I have to convert big numbers in perl from decimal to binary and the other way around. An example number of that length: Dec: 76982379919017706648824420266 Bin: 111110001011111001010101000010011001000010101111001110000000000000000000000000000000000000000000 In the forums i found two functions: sub dec2bin { my $str = unpack("B32", pack("N", shift)); $str =~ s/^0+(?=\d)//; # otherwise you'll get...

Create double by appending binary representations of two ints

c,binary,double,bit-manipulation,arc4random
I'm trying to create a double by appending the binary representations of two ints. This is what I have now: int i = arc4random(); *(&i+1) = arc4random(); double d = *(double*)&i; I hoped the double pointer would also use the value in the &i+1 address, and this is indeed the...

Is floating point precision mutable or invariant?

binary,floating-point,decimal,floating-point-precision,significant-digits
I keep getting mixed answers of whether floating point numbers (a.k.a. float, double or long double) have one and only one value of precision, or have a precision value which can vary. One topic called float vs. double precision seems to imply that floating point precision is an absolute. However,...

In Swift, how do I read an existing binary file into an array?

file,swift,io,binary
As part of my projects, I have a binary data file consisting of a large series of 32 bit integers that one of my classes reads in on initialization. In my C++ library, I read it in with the following initializer: Evaluator::Evaluator() { m_HandNumbers.resize(32487834); ifstream inputReader; inputReader.open("/path/to/file/7CHands.dat", ios::binary); int inputValue;...

Getting the exact position of a specific OpCode in a binary file

c,binary,opcode,objdump,disassembler
Our professor in computer-architecture gave us a sample program which asks for a password. The task is to change the jump-opcode after it compares the entered password and decides if it is okay or not. I wrote a program which can change any byte at a specific place in a...

XOR binary file in Ruby

ruby,file-io,binary
I'm trying to create a "xor" function in Ruby that takes in input a binary file and an hex value and generates a xored binary file in output. File.open("myfile.exe.xor",'w') do |f_xor| f_xor.puts File.open("myfile.exe", 'rb').to_i ^ 0xFF end This code seems not to return the correct xored file as the expected...

find binary permutations in python

python-3.x,binary
I'm looking for a way to find all binary permutations with x amount of '1'. For example: (length = 2) x = 1 (so: find all permutations of 1 and 0 with the length 2 which have one 1 in them) l = ['01', '10'] x = 2 (so: find...

Binary operator '|' cannot be applied to operands of type 'Int' and 'UInt8'

swift,binary,type-conversion,unsigned-integer
I wish to perform simple or logic on 2 bit maps, yet Swift thinks this is wrong: let u: UInt8 = 0b1 let i: Int = 0b10 i | u // Binary operator '|' cannot be applied to operands of type 'Int' and 'UInit8' Any way to conform to type...

Is the most significant decimal digits precision that can be converted to binary and back to decimal without loss of significance 6 or 7.225?

c++,binary,decimal,floating-point-precision,significant-digits
I've come across two different precision formulas for floating-point numbers. floor( (N-1) Log10(2) ) = 6 decimal digits (Single-precision) and Log10(2N) ≈ 7.225 decimal digits (Single-precision) Where N = (24) Significant bits (Single-precision) The first formula is found at the top of page 4 of "IEEE Standard 754 for Binary...

Why isn't this string to binary conversion working?

mysql,sql,binary
I am storing IPv6 addresses as BINARY(16) and trying to search through them using the hexadecimal representation, eg: FFFFFFFF000000000000000000000000. This works: SELECT * FROM ipv6 WHERE HEX(address) = 'FFFFFFFF000000000000000000000000' However, this does not: SELECT * FROM ipv6 WHERE address = CONV('FFFFFFFF000000000000000000000000', 16, 2) No error messages, just doesn't return any...

Store 3 bit binary numbers in C++ array

c++,binary
I have a program that takes 2 inputs, N and myarray[ ]. cin >> N; cin >> myarray[]; In this example say, N=3 which means an integer array of size 3 has to be allocated and suppose that the entries of myarray[ ] are {1,2,3}. Now I have a function...

Express - Return binary data

node.js,pdf,express,binary
I try to return some binary data with Express. In the example, it's a PDF but theorically, this can be any sort of file. But focus on the pdf for the moment. I wrote this code : app.get('*', function (req, res) { getBinaryData(req.url, function (answer) { res.type('pdf'); res.end(new Buffer(answer, 'binary'));...

Bitshifting on little-endian and big-endian [duplicate]

c++,memory,memory-management,binary
This question already has an answer here: Bitwise operators and “endianness” 5 answers Will this: ((0x10203040 >> 24) & 0xFF) == 0x10 always be TRUE on both little-endian and big-endian machines?...

Recode the same value pattern for all variables in Stata

binary,stata,recode
In my dataset, I have a bunch of Yes/No type variables. For some reason, "Yes" is coded as 1 and "No" is coded as 2 instead of 0. Now I want to recode 2 to 0 based on the value label "No". How can I do it without having to...

How to get a floating-point number from its binary representation in Java? [duplicate]

java,binary,floating-point
This question already has an answer here: Convert Double to Binary representation? 4 answers I want to create a binary represenation of a floating-point number and be able to parse that number back when needed. By "binary representation" I do not mean "0.00101" but something like "101000101", that is...

Unsafe or unchecked expressions in an arraylist

java,arraylist,binary,unsafe,unchecked
I'm doing an assignment and I have to create an iterable collection that saves all values of a binary tree between certain tresholds. The binary tree class has a root variable, which is an object of a TreeNode class I've written. The nodes only store integer values. Here are my...