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
3 answers

Finding the maximum area in given binary data

I have a problem with describing algorithm for finding maximum rectangular area of binary data, where 1 occurs k-times more often than 0. Data is always n^2 bits like this: For example data for n = 4 looks like: 1 0 1 0 0 0 1 1 0 1 1 1 1…
user445783
  • 41
  • 3
4
votes
3 answers

Clarification is needed on bitwise not (~) operator

Suppose you have the following C code. unsigned char a = 1; printf("%d\n", ~a); // prints -2 printf("%d\n", a); // prints 1 I am surprised to see -2 printed as a result of ~1 conversion: The opposite of 0000 0001 is 1111 1110. That is anything…
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
4
votes
1 answer

Python: Binary Counting without using inbuilt functions

I have been having some trouble recently with creating a program that counts in binary from 1 to the chosen number. This is my code at the moment: num6 = 1 binStr = '' num5 = input('Please enter a number to be counted to:') while num5 != num6: …
R7mone
  • 41
  • 4
4
votes
4 answers

STL "closest" method?

I'm looking for an STL sort that returns the element "closest" to the target value if the exact value is not present in the container. It needs to be fast, so essentially I'm looking for a slightly modified binary search... I could write it, but it…
dicroce
  • 45,396
  • 28
  • 101
  • 140
4
votes
2 answers

Parsing binary data in Ruby

We're doing a major rewrite of a project previously written in C into Ruby. We have a bunch of C structures, written as C typedefs: struct my_struct { uint32_t foo; uint8_t bar; char baz[80]; } Is there a quick way to load them all up…
Maigio
  • 49
  • 4
4
votes
3 answers

Converting 24 bit integer (2s complement) to 32 bit integer in C++

The dataFile.bin is a binary file with 6-byte records. The first 3 bytes of each record contain the latitude and the last 3 bytes contain the longitude. Each 24 bit value represents radians multiplied by 0X1FFFFF This is a task I've been…
Hulio-G
  • 41
  • 1
  • 1
  • 4
4
votes
1 answer

hash_hmac() with RAW Binary OUTPUT in JavaScript

I have the php code to generate hash_hmac key = base64_encode(hash_hmac('sha1',$public_key, $private_key,TRUE)); I've tried the CryptoJS library to solve it. According to the documentation: var public_key = 'msg', private_key = 'key'; var hash…
Phantr4x
  • 41
  • 3
4
votes
1 answer

How do I convert bit to string in MySQL?

I have a bit field in a table and the data in the field looks like '0100' or '1100', etc. It is just a string of 1's and 0's. The type of the field in MySQL is 'BIT'. I need to read the data as a string. So I simply need to say: select bit_field…
John
  • 1,310
  • 3
  • 32
  • 58
4
votes
6 answers

C# BinaryWrite over SSL

I am trying to respond back to a client with a PDF stored in a MSSQL varbinary(MAX) field. The response works on my localhost and a test server over http connection, but does not work on the production server over https connection. I am using just a…
Eddie
  • 5,050
  • 8
  • 37
  • 46
4
votes
37 answers

Solving Binary Gap using Recursion

I am trying to solve binary gap problem using recursion. It can be easily solved without recursion. But I want to solve this with recursion.The below program takes an integer as input and finds the binary gap. Example: input= 9, Binary form = 1001,…
Zack
  • 2,078
  • 10
  • 33
  • 58
4
votes
2 answers

C++ converting long hex string to binary

I found similar solution here: Missing punctuation from C++ hex2bin and use that answer: std::string hex2bin(std::string const& s) { std::string sOut; sOut.reserve(s.length()/2); std::string extract; for…
Robert
  • 338
  • 5
  • 16
4
votes
2 answers

Why ?attr/colorAccent dose not work below lollipop version?

I have added themes to my application. For this I have used multiple accent colors to add on image button. I have a xml file named fab selector xml , which gives shape and color to image button. But its giving exceptions on this file. 1st exception…
Sid
  • 2,792
  • 9
  • 55
  • 111
4
votes
1 answer

Finding whether bit position is set in C#

I'm getting quite confused here. If I have a number, let's call it 16 here, and I want to check if a particular bit is set. I would do the following: if (16 & (2 ^ bitPosition) == (2 ^ bitPosition)) Right? Why then, for bitPosition = 2, is that…
Seb
  • 410
  • 1
  • 6
  • 20
4
votes
3 answers

How float and double work in IL

When we declare a variable of int for example: int i = 4; The following IL is generated : IL_0001: /* 1A | */ ldc.i4.4 I can understand that 1A is the hexadecimal representation of 4, so am i understanding right that…
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
4
votes
3 answers

Next higher number with one zero bit

Today I've run into this problem, but I couldn't solve it after a period of time. I need some help I have number N. The problem is to find next higher number ( > N ) with only one zero bit in binary. Example: Number 1 can be represented in binary as…
NewJedi
  • 65
  • 1
  • 5
1 2 3
99
100