Questions tagged [bit]

A bit is a single binary digit.

A bit refers to a single binary digit, the smallest possible amount of information. In print is usually represented as either 0 or 1, with many different representations in technology, like the presence or absence of an electric current or magnetic field.

Eight bits form a single , although historically the term has been used for other sizes as well.

3593 questions
1
vote
2 answers

Get Bit values from Byte Array

I have a byte array from which I need to read specific bits and convert to int (see the byte array structure below). Even though the bits information I want to read is in 3 bytes, I tried reading 4 bytes (6-9) as integer and then read the bits from…
Ashu
  • 1,703
  • 4
  • 16
  • 23
1
vote
1 answer

How do I make a bit mask that only masks certain parts (indices) of 32 bits?

I am currently working on a programming assignment in which I have to mask only a certain index of the whole 32-bit number(EX: If I take 8 4-bit numbers into my 32-bit integer, I would have 8 indices with 4 bits in each). I want to be able to print…
SlackStack
  • 79
  • 1
  • 2
  • 12
1
vote
4 answers

nth smallest number with n bits set to 1

There is a sequence of increasing numbers that have the same number of binary 1s in them. Given n (the number of 1 bits set in each number in the series) write an algorithm or C program to find the n'th number in the series. I found this question on…
Anil Katti
  • 1,313
  • 1
  • 14
  • 26
1
vote
0 answers

Send bits using pyserial

I am writing a program to send DALI commands via serial port. So, at this case, I got various problems. First of all, DALI commands are messages of 19 bits for questions (1 start bit, 8 adress bits, 8 command bits and 2 stop bits) and 11 bits for…
1
vote
1 answer

Convert 16 bit integer/data to 12 bit integer/data in Swift

I currently have a function that intakes UInt16 and converts it into data to send over bluetooth. Here is a snippet: var integerToSend = UInt16(10) let commandID = 0x07 let data = NSMutableData(bytes: &commandID, length:…
riceman89
  • 179
  • 1
  • 13
1
vote
3 answers

Open specific file with the specific words (16 bits) structure

I have a specific binary? file format containing datas about the configuration used to take a picture with a custom camera. This file format is named DAI and contains for example values of offset/gain/etc... I am using a black-box script in java to…
1
vote
3 answers

Bitwise operators - when/how do you use the operators &, |, ^, >> etc?

I know what they do, I just don't understand when you'd get a use for them..
DarkLightA
  • 14,980
  • 18
  • 49
  • 57
1
vote
1 answer

Convering Big Endian Formatted Bits to Intended Decimal Value While Ignoring First Bit

I am a reading binary file and trying to convert from IBM 4 Byte floating point to double in C++. How exactly would one use the first byte of IBM data to find the ccccccc in the given picture IBM to value conversion chart The code below gives an…
CrippledTable
  • 784
  • 5
  • 20
1
vote
0 answers

Reading / Computing Hex received over RS232

I am using Docklight Scripting to put together a VBScript that communicates with a device via RS232. All the commands are sent in Hex. When I want to read from the device, I send a 32-bit address, a 16-bit read length, and an 8-bit checksum. When I…
Jonathan L
  • 11
  • 1
1
vote
1 answer

How to encode a number into custom range

I'm in the need to write a dynamic compression for float values. The dynamic part is, that the end user will provide bounds and precision and the rest has to be handled. The first part is to figure out how many bits are needed. The formula I use is…
Yosh Synergi
  • 314
  • 3
  • 12
1
vote
2 answers

How to compare a memory bits in C++?

I need help with a memory bit comparison function. I bought a LED Matrix here with 4 x HT1632C chips and I'm using it on my Arduino Mega2560. There're no code available for this chipset (it's not the same as HT1632) and I'm writing on my own. I have…
Trunet
  • 176
  • 6
1
vote
3 answers

Algorithms :XOR operation

You are given a sum S and X , you need to find , if it there exist two numbers a and b such that a+b = S and a^b = X I used a loop upto S/2 and check if it is possible or not for(int i=0;i<=s/2;i++) { if(i^(s-i)==X) return…
Subham Gupta
  • 53
  • 1
  • 5
1
vote
1 answer

Why does my BitSet have a size of 0?

Here is my code. What I am trying to do is process the bytes from my ByteBuffer using a BitSet. The ByteBuffer is loaded from DynamoDB(With the DynamoDBMapper) ByteBuffer buffer = ....... System.out.println("Array length is " +…
committedandroider
  • 8,711
  • 14
  • 71
  • 126
1
vote
2 answers

How to store integer in fewest bits possible in Java

I have numbers lower than 16 and I want to store them the smallest way possible. I currently convert my integer to a byte but I don't need the whole byte. I think I only need 4 bits to hold my number. I want to use as little of a byte as I…
ProgrammingCuber
  • 377
  • 4
  • 14
1
vote
3 answers

How do I locate black rectangles in a grid and extract the binary code from that

i'm working in a project to recognize a bit code from an image like this, where black rectangle represents 0 bit, and white (white space, not visible) 1 bit. Somebody have any idea to process the image in order to extract this informations? My…
Denis
  • 11
  • 1
  • 2