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
1 answer

What is best way to convert two uint8 bytes to uint16 byte in arduino?

I'm using Arduino with ESP32 and I'm still at the beginner level. I have two bytes which are uint8 and are variables, I want to convert them to uint16. Which way would be best to do it? I think bitshift should be good uint8_t first = 0xFF; //lets…
TheAfrizzz
  • 23
  • 5
1
vote
1 answer

How do I find the position of the least significant bit in which 2 numbers differ in python?

I have two binary numbers 01110 and 10010 It is easy to see that the first position they differ is the third from the right. How do I find this in python? Let's say, I would hve something like sdb(a, b) and that would return 3 in this case. Are…
topkek
  • 149
  • 9
1
vote
1 answer

What is the 32 bit binary equivalent of -41.25?

So I'm not sure how to do this, but I'll try. Where do I go wrong? So I know double has 1 bit for sign, 8 bits for exponent, 23 bits for the fraction. So since it's negative, it starts with a 1. 41 is equal to 101001 in binary. 0.125 is equal to…
Jwan622
  • 11,015
  • 21
  • 88
  • 181
1
vote
2 answers

What is the fastest way to check bits in variable using bitwise operations?

For example I have short (2 bytes = 16 bits) variable: (in my project this is sequence of 00, 01 and 10's) 0001010101101001 = 0001.0101|0110.1001 And I want to check if this variable contains sequence of bits, for example I need '01010101' (this is…
1
vote
1 answer

Bitshifts: how to convert decimal to bitshift value in Java

I have a REST API which provides values as decimal numbers and they need to be converted to strings using a map of bitshift operators: EXCEPT DISABLED 1 << 0 EXCEPT MOTO 1 << 1 EXCEPT LOADING 1 << 2 EXCEPT…
vrgrg
  • 566
  • 4
  • 17
1
vote
1 answer

Bit Testing.Counting the bits

Why does it print that bit number 6 of 47(00101111) is 1.Counting the bits starts from the right side starting with 1? #include #include int main() { int mask1,mask2; //bit testing; …
Michael
  • 82
  • 5
1
vote
3 answers

Read bits between bytes

I am trying to read bits from a buffer of bytes. So far masking and shifting has worked however I am not sure what to do about a value that appear between bytes, such as, ... 11001001 11101101 ... (read 8 bits from the buffer with 4 bit offset) …
Max Paython
  • 1,595
  • 2
  • 13
  • 25
1
vote
2 answers

Interleave 2 32-bit integers into 64 integer

So I was given the task of interleaving two 32-bit integer into one, like this: a_31,...,a_0 and b_31,...,b_0, return the 64-bit long that contains their bits interleaved: a_31,b_31,a_30,b_30,...,a_0,b_0. I tried doing it by taking the MSB from…
Rika
  • 75
  • 3
1
vote
1 answer

Finding the number of bits required to save int number

So my problem is that i have to recursively find the number of bits, that are required to display / save a number e.g. 4(10)=100(2) so 3 bits would be needed. I think i already know how i am supposed to do it, but my code still doesnt work. Here is…
vader69
  • 27
  • 3
1
vote
1 answer

Image compression

I have a colour palette such that there are 4 colours. These colours are white, green, yellow and orange. The RBG values for these colours respectively are (255, 255, 255) (0, 255, 0) (255, 120, 0) (255, 255, 0). An image is an 8 x 8 pixel RGB…
user12183419
1
vote
5 answers

Bit Manipulation, find another shortest array whose binarian is same as the given array's binarian

Given an array A, its binarian(A) is defined as 2^A[0] + 2^A[1] + .... 2^A[n]; Questions asks to find anther shortest array B whose binarian(B) is same as A's. For example, A=[1,0,2,0,0,2],thus if B=[3,2,0], this satisfies the requirements, and the…
Jason
  • 39
  • 8
1
vote
2 answers

Function to generate the corresponding mask for a bit field

I have a 32 bit register R with various bit fields declared as follows: typedef union { uint32_t raw; struct { uint32_t F1 : 0x4; uint32_t F2 : 0x8; uint32_t F3 : 0x8; uint32_t F4 : 0xC; } } reg1 I also have a regWrite macro…
1
vote
2 answers

Encoding/Decoding data in c++ using encoder/decoder logic gate rules

Is there a way to deal with bits in c++(c is ok too!) in a way to emulate an encoder(or decoder) logic gate? For example: encoding a byte(8 bits) into only 3 bits, or a word (16 bits) into 4 bits only and vise versa. exactly in the way encoder and…
Muhammad Nihad
  • 95
  • 2
  • 12
1
vote
1 answer

Understanding bit-level float multiplication in C?

I tried to implement float_twice(float_bits x) in C, which multiplies x by 2 in bit-level. I compared the result of float_twice and the real float multiplication implemented in C, but found a difference. float_twice(0X800001) yields 0X1000001, and…
Kyle
  • 13
  • 2
1
vote
2 answers

Converting from smaller data type to bigger and vice versa

I have this C code which tries to store a signed short in signed char. signed char range is [-128,127] and signed short range is [-32768, 32767]. signed char sChar = SCHAR_MAX; printf("Signed Char: %d", sChar); signed short sShort =…
Yoshikage Kira
  • 1,070
  • 1
  • 12
  • 20