Im having trouble with a Bit write function inside a Library

Hi, im writing a library and I need a bit write function for inside the library. I must have a 8 bit a 16 bit and a 32 bit function, so I thought of Polymorphism.

This are the functions I came with:

uint8_t DebouncedEdgeDetector_16Bit::BitWrite(uint8_t Var, uint8_t Bit, bool Data)
{
    uint8_t bitmask = ~(1 << Bit);
    uint8_t data = Data << Bit;
    
    Var = (Var & bitmask) |  data;
    
    return Var;
}

uint16_t DebouncedEdgeDetector_16Bit::BitWrite(uint16_t Var, uint8_t Bit, bool Data)
{
    uint16_t bitmask = ~(1 << Bit);
    uint16_t data = Data << Bit;
    
    Var = (Var & bitmask) |  data;
    
    return Var;
}

uint32_t DebouncedEdgeDetector_16Bit::BitWrite(uint32_t Var, uint8_t Bit, bool Data)
{
    
    uint32_t bitmask = (1 << Bit);
    
    uint32_t data = Data << Bit;
    
    Var = (Var & bitmask) |  data;
    
    return Var;
}

The thing is that I’m now trying to use the 32 bit write, but it always returns 0

can someone help me with this??

thanks!

Edit: I just realized that I didn’t posted this in programming questions… Sorry

You forgot the "not" the bitmask in the 32bit version.

It was there, i removed while testing printing the values, but even dough it is not there, the bit mask is not working, i tried doing the bitmask, and then immediatly print the 32 bit value to the serial port, and I always recieved 0 :o

Ps: I know I can use Arduino bitWrite function but I'm doing this to learn..

You need:

   uint32_t bitmask = (1UL << Bit);

In the absence of casts or constant modifiers, constants in expressions, and the results thereof, are assumed to be “int” quantities. Shift an int containing 1 left by more than 15 bits, and you get zero.
Using “1UL” makes the 1 an unsigned long, and it should work.