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

Best way to move 8 bits into 8 individual bytes

I have a status register with 8 bits. I would like to move each individual bit to a byte for further processing. Seems like it should be easy but every solution I come up with is convoluted. I was thinking about iterating through the bits with a for…
1
vote
2 answers

How many bits are in a logical address?

Alright, so I've done some searching around Stack and cannot find the answer to this question. It's something that was mentioned in class, but the professor did not specifically say how to go about figuring this out. If we assume a system is 64bit,…
rybo
  • 1,161
  • 2
  • 10
  • 14
1
vote
2 answers

Read First n Bits in a Byte Array in Scala

I have a Byte array as for example: 0 240 167 43 200 209 57 213 1 89 182 103 60 43 0 0 I would now want to read the first 3 bits of this Byte array: Here is how I read this as a Byte array: val bytes = "0 240 167 43 200 209 57 213 1 89 182 103 60…
joesan
  • 13,963
  • 27
  • 95
  • 232
1
vote
1 answer

MATLAB: extract most significant bits

I am learning MATLAB and am facing problem about extracting most significant bits from a given double. I saw getmsb function. But, is there a function that can give me say 5 most significant bits? Anil.
Anil Katti
  • 1,313
  • 1
  • 14
  • 26
1
vote
2 answers

Using first bit as a flag in an unsigned int

I am trying to use the first bit of an unsigned int as a flag if the client as server should re-key for their encryption keys. I would like to use the rest of the unsigned int as the length for the remaining data that is being sent. Currently I am…
benthecarman
  • 125
  • 7
1
vote
1 answer

How to manipulate the bits in a long?

I want to transform a long to binary code, then change some bits and get the long again. I have found this post Java long to binary but I still can't achieve what I want. I think there is two ways to achieve my goal: Going from long to bitset and…
J.erome
  • 688
  • 7
  • 26
1
vote
1 answer

How to find the leftmost bit of an number in one line

How to find out the leftmost bit and rightmost bit of an number in one line of code ? Well we can traverse an loop to find out the leftmost set bit by leftshift but how to do it in one line to make an another no. whose leftmost bit / rightmost bit…
sagar saini
  • 107
  • 1
  • 7
1
vote
1 answer

Bit alignment, 8-bools-in-1

I'm trying to compile the following code: union Bool { bool b[8] : 8; // (1) bool b0,b1,b2,b3,b4,b5,b6,b7 : 1; }; However the line (1) doesn't compile, whats the syntax for bit aligning an array?
Skeen
  • 4,614
  • 5
  • 41
  • 67
1
vote
3 answers

Check even parity from byte

I've found a piece of code on Stackoverflow and edited it to my needs. source: How to check if value has even parity of bits or odd? It works like a charm, but I can't get my head around WHY it works. I tried writing it out, with example byte…
MrEmper
  • 225
  • 1
  • 4
  • 18
1
vote
0 answers

Is there any way to send only one bit of data by nodejs?

I'm setting up a new nodejs udp server, and want to send only one bit of data to another udp client. But I find that the smallest size of Buffer is one Byte which contains 8 bits. Is there any way to send only one bit of data in nodejs?
刘腾辉
  • 11
  • 2
1
vote
1 answer

What's the difference between &<< and << operators in Swift?

What's the difference between &<< and << operators in Swift? It seems like they return the same results: print(2 << 3) // 16 print(2 &<< 3) // 16
Dmitry
  • 14,306
  • 23
  • 105
  • 189
1
vote
0 answers

Utilizing Redis for setting and retrieving bits

Main idea is to store random bits to redis and retrieve and drop them when required. Pseudocode which sets the boolean value to the next position of the bitcollection. This way I should have a growing collection of bits. Setter: boolean =…
Denny Mueller
  • 3,505
  • 5
  • 36
  • 67
1
vote
0 answers

Python bit serialziation

I want to serialize a few variables into an array of bytes. My problem is that this serialziation has to be done with different values of bits. For example. Member 1 -> 4 bits Member 2 -> 1 bit Memebr 3 -> 32 bits I have tried struck.pack solution…
Xabi E
  • 251
  • 2
  • 3
  • 15
1
vote
2 answers

Bit circular shift

I am currently learning on bit-wise operations, and i am tasked to do a left rotate of 4-bit integer. My code for a 4bit left rotate is private static int BITS_IN_INTEGER = 4; private static int leftRotate(int x, int n) { return (x << n) | (x >>…
user3413646
  • 167
  • 2
  • 11
1
vote
0 answers

Dynamically change the mask for the selected bytes

Say for example I have a hex 1F40 = 8000, I want to show it in a textbox as 1111.1111.1111.1111, because I dont want to hide/mask any part of it. The user should be allowed to change that if they wish. Like 1111.1111.0000.1111 = 7936 for example if…
T.Janson
  • 31
  • 1
  • 5