Custom bit widths

How do i create basic datatypes with custom bit widths?

Example: I need a 20 bit signed integer.

I am modeling hardware that can have custom bit widths. How do I do it in C++?
You will need to write a class that wraps an int and ensures that the value never exceeds the range of a 20-bit signed integer.
You can also use bitfields/bitsets and manually convert the bits into whatever type you want them to be.
a bit field

1
2
3
struct bit_field{
    unsigned field : 20; // 20 bit 
}
Topic archived. No new replies allowed.