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

http content type, and binary data

I thought I knew this already but now I'm not sure: Is all content sent over http always encoded to character data? ie, if my content type is a binary file type, is it always converted to binhex, or is it possible to send "actual" binary data across…
Brady Moritz
  • 8,624
  • 8
  • 66
  • 100
4
votes
3 answers

Matlab binary encoding

I have a vector containing a series of integers, and what I want to do is take all numbers, convert them into their corresponding binary forms, and concatenate all of the resulting binary values together. Is there any easy way to do this? e.g. a=[1…
GobiasKoffi
  • 4,014
  • 14
  • 59
  • 66
4
votes
2 answers

std::ios::binary or std::ifstream::binary and similar?

While searching for file reading examples in C++, I notice that many examples use std::ios::binary vs std::ifstream::binary std::ios::beg vs your_file_stream.beg std::ios::end vs your_file_stream.end Are there any differences in these examples,…
João Pires
  • 927
  • 1
  • 5
  • 16
4
votes
4 answers

Decimal-to-binary conversion

I want to convert decimal numbers to binary numbers. I want to store them in an array. First I need to create an array that has a certain length so that I can store the binary numbers. After that I perform the conversion, here is how I do it: public…
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
4
votes
1 answer

What are the benefits of Gray code in evolutionary computation?

Books and tutorials on genetic algorithms explain that encoding an integer in a binary genome using Gray code is often better than using standard base 2. The reason given is that a change of +1 or -1 in the encoded integer, requires only one bit…
4
votes
1 answer

Could someone explain to me what the following Java code is doing?

byte s[] = getByteArray() for(.....) Integer.toHexString((0x000000ff & s[i]) | 0xffffff00).substring(6); I understand that you are trying to convert the byte into hex string. What I don't understand is how that is done. For instance if s[i] was…
user_1357
  • 7,766
  • 13
  • 63
  • 106
4
votes
9 answers

how to loop through the digits of a binary number?

I have a binary number 1011011, how can I loop through all these binary digits one after the other ? I know how to do this for decimal integers by using modulo and division.
Attilah
  • 17,632
  • 38
  • 139
  • 202
4
votes
4 answers

Count non-symmetric bytes

I am looking for a clean way to list the (8 bit) integers whose binary representation is not the same as another integer up to rotation and reflection. For example the list will probably start as 0 1 (2=10b is skipped because you can rotate the bits…
John Smith
  • 12,491
  • 18
  • 65
  • 111
4
votes
2 answers

Binarize integer in a pandas dataframe

I have a pandas dataframe and want to add a new column. For all values in 'number' which are smaller than 15 I want to add 1, for all values which are greater, 0. I tried different methods, but I don't receive the desired result.Especially, because…
matthew
  • 399
  • 1
  • 7
  • 15
4
votes
1 answer

Binary vs Integer - as primary key?

I was wondering if there are any obvious pros and cons one should be aware about, while choosing to use a Binary type as a primary key, while being RANDOMIZED. Which means, new inserts will have random 4 bytes as their PK - versus having a sequence…
Doori Bar
  • 873
  • 2
  • 13
  • 20
4
votes
2 answers

Why does a Python bytearray work with value >= 256

The Python documentation for bytearray states: The bytearray type is a mutable sequence of integers in the range 0 <= x < 256. However the following code suggests values can be >= 256. I store a 9 bit binary number which has a maximum value of:…
Jack
  • 10,313
  • 15
  • 75
  • 118
4
votes
1 answer

Reversing an old file format Inbox X

I’m trying to reverse engineer an old medical imaging format called Stentor for interoperability. It was designed by a company of the same name who was subsequently bought by Phillips. But Phillips has forgotten how to read Stentor files. I have a…
Kyle Fritz
  • 241
  • 2
  • 11
4
votes
1 answer

How to pivot pandas DataFrame column to create binary "value table"?

I have the following pandas dataframe: import pandas as pd df = pd.read_csv("filename.csv") df A B C D E 0 a 0.469112 -0.282863 -1.509059 cat 1 c -1.135632 1.212112 -0.173215 dog 2 e 0.119209…
ShanZhengYang
  • 16,511
  • 49
  • 132
  • 234
4
votes
2 answers

Python - Best way to find the 1d center of mass in a binary numpy array

Suppose I have the following Numpy array, in which I have one and only one continuous slice of 1s: import numpy as np x = np.array([0,0,0,0,1,1,1,0,0,0], dtype=1) and I want to find the index of the 1D center of mass of the 1 elements. I could type…
fmonegaglia
  • 2,749
  • 2
  • 24
  • 34
4
votes
3 answers

String of 0's and 1's to File as bits

I am working on a Huffman java application and i'm almost done. I have one problem though. I need to save a String of something like: "101011101010" to a file. When I save it with my current code it saves it as characters which take up 1 byte every…
Luud van Keulen
  • 1,204
  • 12
  • 38