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

Java code or lib to decode a binary-coded decimal (BCD) from a String

I have a string consisting of 1's ('\u0031') and 0's('\u0030') that represents a BCD value. Specifically, the string is 112 characters worth of 1's and 0's and I need to extract either 8 or 16 of these at a time and decode them from BCD to…
T to the J
4
votes
4 answers

How to count number of zeros at the left of each one in an Numpy array

I have a numpy binary array like this: Array A = [1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0] I would like to count how many 0s are there at the left of each 1, and return it in an other array that would look like this for this for this…
user2505650
  • 1,293
  • 6
  • 20
  • 38
4
votes
2 answers

Why does this code return two different values doing the same?

#include #include #include int main() { double a; double b; double q0 = 0.5 * M_PI + 0.5 * -2.1500000405000002; double q1 = 0.5 * M_PI + 0.5 * 0.0000000000000000; double w0 = 0.5 * M_PI + 0.5 *…
Rafael
  • 402
  • 5
  • 17
4
votes
3 answers

How can i perform mathematical operations on a base n number system in R

I want to perform some calculations in base 3 and need to have addition subtraction in that base. eg. 2+2 should become 11 in base 3
whisperer
  • 587
  • 7
  • 13
4
votes
2 answers

C++, weird behavior while reading binary ifstream

For my first question here, I'd like to talk about reading binary files in C++; I'm recoding an ID3 tag library. I'm parsing the header which is a binary file, the first 10bytes are as follow: ID3 = 3 bytes = constant identifier 0xXXXX = 2 bytes…
Arnaud M
  • 43
  • 3
4
votes
2 answers

Elixir - Handling binaries, strings, and charlists (project euler 8)

I was trying to solve some project Euler problems with Elixir but I stumbled upon a hard one I can't solve, and I think it's largely due to the fact that I still don't understand strings, chars and binaries. Even after reading the docs on bin,…
Frank Kair
  • 451
  • 4
  • 13
4
votes
3 answers

Convert Binary to Decimal in Objective C

I have binary sequence in a string. How to convert it in decimal. Is there any built in function in Objective C ?
Ruchit Patel
  • 1,030
  • 1
  • 12
  • 24
4
votes
1 answer

How to convert binary floating points to decimal fractions?

I'm stuck on a homework assignment; I need to convert a binary float to a decimal fraction. I feel like I understand the process, but I'm not getting the right answer. Here's my thought process. I have the binary float: 0 000 101 The bias for a…
Grav
  • 461
  • 6
  • 18
4
votes
2 answers

python/numpy generated binary file to be read by C

I am creating a 5*7 integer matrix binary file in python called random_from_python_int.dat, I then read this binary file from C. Somehow I can not get the correct numbers Here is my python code to generate this matrix: import numpy as…
harmony
  • 111
  • 1
  • 9
4
votes
2 answers

BCD to Decimal And Decimal to BCD

I am writing a library for RTC module in Arduino where the data is stored in BCD. I know how the Decimal number is converted into BCD but having some problem while writing it programmatically. After searching the internet I got two formulas which…
Himadri Ganguly
  • 715
  • 4
  • 11
  • 31
4
votes
2 answers

How can I store images in mongodb with node.js?

I'm using the current application stack: node.js, mongodb, express (for node.js), and mongoose (for node.js ... gives me orm capabilities) I'm getting used to everything and have the regular CRUD stuff working. However, I can't figure out how to…
Travis
  • 7,391
  • 12
  • 43
  • 52
4
votes
2 answers

Confusing about create an app which has version for both iphone and iPad

I am creating an app which has version for both iPhone and iPad, iPad version has different GUI and some more functionality. Currently, I separate them in 2 projects. After reading this article: Jump from iphone to ipad development... And see: "All…
Son Nguyen
  • 3,481
  • 4
  • 33
  • 47
4
votes
1 answer

How to open a image in Go to get binary data of black and white pixels?

I've been trying for sometime to open an image in binary mode with Go. In Python I'd use the Pillow and image.open() (rb mode). Example. img = Image.open("PNG.png") pix = img.getdata() #where 0 is black and 1 is white pixel That would open the…
reticentroot
  • 3,612
  • 2
  • 22
  • 39
4
votes
3 answers

C++ Reading a PDF file

I'm using the following code to read the content of a PDF file: string document; FILE * f; f = fopen ( path , "rb"); unsigned char buffer[1024]; while(!feof(f)){ int bytes = fread(buffer,1,1024,f); for(int i = 0; i < bytes; i++){ …
Van Coding
  • 24,244
  • 24
  • 88
  • 132
4
votes
2 answers

Java Recursive Decimal to Binary Function Printing Backwards

I am coding a Lab exercise for one of my classes. The question asks to "Write a recursive function convert a decimal number into a binary number, printing the binary number" Using the constructor public static void decToBin(int num){} Current…
BigChemist
  • 43
  • 4