Questions tagged [binary]

Binary, the base-2 numeral system, represents numbers using two symbols: 0 and 1. For compiled computer programs, use the "executable" tag instead.

Binary is the base-2 positional numeral system. It represents numbers using two symbols: 0 and 1.

Computers use binary in digital circuitry using logic gates, where the symbols translate to states of off (0) and on (1).

Here are binary numbers corresponding to 0 to 10 in the decimal system:

Decimal   Binary
-------   ------
      0        0
      1        1
      2       10
      3       11
      4      100
      5      101
      6      110
      7      111
      8     1000
      9     1001
     10     1010

Other tags

14710 questions
4
votes
2 answers

Convert two's complement, left justified integer into regular binary

I am programming a Raspberry Pi 3 in C++ and Qt. I am using the wiringPi library to interface with an I2C accelerometer (which I am using to compare tilt angle values but not measure the angle degrees). I need to determine if one accelerometer…
MarqTwine
  • 41
  • 1
  • 4
4
votes
3 answers

Is there an easy way of using binary numbers in Python?

I have to work using binary formated numbers and I'm wondering if there's a simple and easy built in way to use them. I am aware of the bytearray but it works with byte type and it is absolutely not intuitive (at least for me). So, is there any way…
Berbus
  • 160
  • 3
  • 20
4
votes
1 answer

Finding null space of binary matrix in python

In factoring methods based on the quadratic sieve, finding the left null space of a binary matrix (values computed mod 2) is a crucial step. (This is also the null space of the transpose.) Does numpy or scipy have tools to do this quickly? For…
qwr
  • 9,525
  • 5
  • 58
  • 102
4
votes
3 answers

More Pythonic Way to Convert 24 bit ints to 32 bit ints

I currently use the following code to convert an array of bytes which represent little endian signed 24 bit integers into a list of signed 32 bit integers. xs = list(bytes_object) ys = [xs[x:x+3] + [255] if xs[x+2] & 128 else xs[x:x+3] + [0] …
scruffaluff
  • 345
  • 4
  • 20
4
votes
1 answer

Write numpy array to binary file efficiently

I need an efficient solution for writing a large amount of data to a binary file. Currently I use the numpy method .tofile, which consumes most of the runtime. My MWE: import numpy as np def writeCFloat(f, ndarray): np.asarray(ndarray,…
Magdalena
  • 45
  • 1
  • 5
4
votes
1 answer

How to parse OpenFoam polyMesh in binary stream format?

I'm working on a tool that needs to parse the OpenFoam polyMesh files (points, faces, boundary). At this moment the tool can only parse the ASCII format of the polyMesh files and what I will need to add is the support for binary as well. How can I…
Daniel
  • 544
  • 1
  • 10
  • 21
4
votes
2 answers

How do I convert the data of a Node tree into an ordered ArrayList?

public class Node { private int data; public int getData() { return data; } private Node left; private Node right; public Node(int d, Node l, Node r) { data = d; left = l; right = r; } // Deep copy constructor public Node(Node o)…
ismael oliva
  • 97
  • 1
  • 3
  • 11
4
votes
3 answers

Python numpy 'Expected an input array of unsigned byte data type'

I want to generate all binary numbers within a specific range, the code I have so far is: int2binary = {} largest_number = pow(2,16) binary = np.unpackbits(np.array([range(largest_number)],dtype=np.uint16).T,axis=1) As the numbers generated will be…
user5134772
4
votes
2 answers

xtlogit in R - logit fixed effects

I'm trying to figure out how to perform a fixed effect logit regression in R (analogously to Stata's xtlogit command). I read of several packages such as "pglm" or "bife" but couldn't get my model to run. My data is saved as a data frame and looks…
Neicooo
  • 197
  • 1
  • 9
4
votes
5 answers

How do alternative positional base systems (hexadecimal, octal, binary) work? How do I convert them to decimal?

I haven't learned this in programming class before, but now I need to know it. What are some good resources for learning these numbers and how to convert them? I pretty much am going to memorise these like the times table.
Strawberry
  • 66,024
  • 56
  • 149
  • 197
4
votes
2 answers

linux binary independent of shared libraries

I have a C++ program that depends on quite a few libraries (some common system libraries like libjpeg some personal libraries that are not installed system wide). The Program compiles well on machine A (Debian Squeeze). I would like to run the…
Joekk3
  • 41
  • 2
4
votes
1 answer

Print an integer tensor in binary

I have a tensor of type tf.int32 I would like to use tf.Print but I need the result to be in binary. Is this even possible? It is for debugging. Example: constant = tf.constant(5) #magic tf.Print(constant) # prints 101
dtracers
  • 1,534
  • 3
  • 17
  • 37
4
votes
0 answers

writing python request using "post" to flask server as binary file

My client use this code to upload file and some json to a flask server : datas = {'CurrentMail': "AA", 'STRUserUUID1': "BB", 'FirstName': "ZZ", 'LastName': "ZZ", 'EE': "RR", 'JobRole': "TT" } #sending user infos to app server using python…
MouIdri
  • 1,300
  • 1
  • 18
  • 37
4
votes
2 answers

How to do binary addition in bash

I am trying to add two 32 bit binary numbers. One of them is a constant (address_range_in_binary) , and another one is an element of an array (IPinEachSubnet[$val]) I am trying to follow the instructions here, but I could not figure out how to get…
screenslaver
  • 563
  • 1
  • 8
  • 17
4
votes
2 answers

Why and How, is this C program showing 7.21 accurately?

I am familiar with the fact that decimal fractions often don't convert neatly into binary, and so an approximation is stored and when converted back into decimal is a bit off from the original number. I believe 0.21 would be an example of such a…
barlop
  • 12,887
  • 8
  • 80
  • 109