8 bit integers

for a MIDI project i need to define some variables as a 8-bit unsigned integer. this is mainly to save up storage and to prevent error-anticipation programming

is there any simpel way of doing this and with a specifik amount of bits (2,4,7)??

uint8_t is the type your looking for. It makes no sense to define a type with 7 bits as it would use 8 bits anyway. 2 and 4 bits could be stored as bits within uint8_t but that involves programming overhead every time you access the value so you have to decide for yourself if it's worth it or if you just use the bigger type and use a bit more memory.

You can define fields in structs that are a specific number of bits with the ':' syntax, but not outside of a struct.

struct foo_struct
{
  unsigned int a : 3 ;
  unsigned int b : 2 ;
} foo ;