C code No built-in functions, Only bit manipulation (explained)
Code

# Code
```c []
int smallestNumber(int n) {
    int count = 0; // number of 1's in "n"
    int lastone = 0; // refers to last bit with value 1 
                    // in "n" starting from right
    int m = n;

    for(int i = 1 ; i < 11 ; i++){
        if(m & 1){
            lastone=i;
            count++;
        }
        m >>= 1;
    }
// this line below means we only encounter bits with 1 values
// before reaching the first bit with 0 value
    if(lastone==count)return n;
    
    int result = 0;
    for(int j = 0 ; j < lastone; j++){
        // shift left and set LSB to 1
        result = (result << 1) | 1;
    }
    return result;
    
}
```
['Bit Manipulation', 'C']