Questions tagged [bit-fields]

A bit field is used to compactly store multiple logical values as a short series of bits where each of the single bits can be addressed separately.

A bit field is used to represent and store a set of known width and logically grouped set of values. These fields can then be addressed individually in the code. A common use of such a construct is flags.

In language such as C and C++, bit fields can also be used to abstract and interop with specific hardware.

857 questions
0
votes
1 answer

Alignment of the mixed bit fields and fields of structures in big-endian and little-endian

from my previous experience i understood the following: // if i have structure in big-endian system, look like this: typedef struct { unsigned long a: t1, b: t2, c: t3, d: t4, //... z: tn; }…
ltWolfik
  • 330
  • 2
  • 9
0
votes
1 answer

How to handle customized floating point using union(bit fields)?

I am analyzing a predecessor codes(codes run on microcontroller) handling pointing point, but I don't understand how things work. I have got to know how to convert flat to decimal and the other way around. However, what he did was used customized…
Jin
  • 113
  • 11
0
votes
1 answer

Is there a way to deflate & map bit-mapped database columns into scala objects via slick

This is in continuation to the following post: How to combine multiple columns in one case class field when using lifted embedding? I am a great fan of bit fields, wants to use this logic in a project where I am using slick-macros. Unfortunately…
sgireddy
  • 155
  • 10
0
votes
2 answers

Why unsigned int value in c bit-field became signed value?

#include #include struct Foo { int a : 2; int b : 2; int c : 2; int d : 2; }; int main() { Foo foo; foo.d = 2; std::cout << sizeof(foo) << std::endl; std::cout << foo.d << std::endl; return…
Jichao
  • 40,341
  • 47
  • 125
  • 198
0
votes
2 answers

Bit fields in a union - how portable is this?

I got a bit field with a bunch of flags, and I need a quick and dirty way to set everything to zero, so instead of blindly casting the struct to an integer, I decided it would be "better" to put the bit fields in a union with an actual integer.…
user2341104
0
votes
4 answers

Bit fields in C and C++: where are they used?

I am working with C and C++ for some time. While learning the basics you can bump into such interesting thing as bit fields. Usage of bit fields in programming practice has somehow controversial character. In which kind of situations this low-level…
Ilya Tereschuk
  • 1,204
  • 1
  • 9
  • 21
0
votes
1 answer

Convert Bit-field to list in python

I'm not a dev... And wouldlike a function, to convert a bit value, into a list of integer : let say I have the following possible bits : 1 2 4 8 I would like a function, bit2list(7) that would give back (1;2;4) or bit2list(9) should give back…
OpenStove
  • 714
  • 1
  • 11
  • 22
0
votes
1 answer

How do I determine what is the source of Input Device in android?

I have to work with the InputDevice.getSources() method to determine the type (source) of InputDevice. But instead of returning a predetermined integer, it returns a combined bitfield, for example: 16786707 (this is an actual value from my…
Pixelapp
  • 193
  • 1
  • 10
0
votes
1 answer

C# need to increment (with overflow) and individually access 2bits

I want to use 2bits to switch on and off parts of a mathematical statement in a loop. Kinda like: Result[i] = someMath*bits[0] + someMath*bits[1] (bits[n] refers to index n, not a value of n) Using them as flags but then in each loop I then want to…
Lamar Latrell
  • 1,669
  • 13
  • 28
0
votes
1 answer

Bit field for use in query string

I've got a 256 character long string I'm using as bit field that I want to shrink with JavaScript so I can use it as part of a query string in a url. I'm not sure what the best/most efficient way to do this is. I think I want something similar to…
Stuart Memo
  • 1,138
  • 4
  • 14
  • 30
0
votes
2 answers

Implementing a half precision floating point number in C++

I am trying to implement a simple half precision floating point type, entirely for storage purposes (no arithmetic, converts to double implicitly), but I get weird behavior. I get completely wrong values for Half between -0.5 and 0.5. Also I get a…
user2341104
0
votes
8 answers

What's the best way to return multiple enum values? (java and C#)

more of original content deleted to make question easier to reference: So I have a House class that has a method House.buy(Person p), causing the person to buy the house. I want to know if its possible for the Person to buy the House, so I also have…
Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
0
votes
2 answers

c bitfields strange behaviour with long int in struct

i am observing strange behaviour when i run the following code. i create a bitfield by using a struct, where i want to use 52 bits, so i use long int. The size of long int is 64 bits on my system, i check it inside the code. Somehow when i try to…
zabeltech
  • 963
  • 11
  • 27
0
votes
2 answers

how to set values in bitfield set variables in a structure?

I have written the code below on Qt,when I put values in it it program.exe stops working. struct aim { int i : 1; int j : 1; }; int main() { aim missed; printf("Enter value of i :: "); scanf("%u",missed.i); …
Satya Kumar
  • 179
  • 1
  • 4
  • 19
0
votes
1 answer

Get ints (of various sizes) from boolean array

OK, say I have a boolean array called bits, and an int called cursor I know I can access individual bits by using bits[cursor], and that I can use bit logic to get larger datatypes from bits, for example: short result = (bits[cursor] << 3) | …
Pez
  • 172
  • 2
  • 15