Finish Week3

This commit is contained in:
Citlali del Rey 2024-02-07 17:42:18 -08:00
parent edf292ea01
commit abf9c56110
Signed by: nullobsi
GPG key ID: 933A1F44222C2634

View file

@ -90,3 +90,20 @@ char* addBinary(char *a, char *b) {
return &outString[l_x-i];
}
int minBitFlips(int start, int goal) {
// Use XOR operation to get the correct mask
uint32_t mask = start ^ goal;
// Number of flips
uint8_t flips = 0;
// Tally all of the 1's
while (mask > 0) {
flips += (mask&1);
mask >>= 1;
}
// Return value.
return flips;
}