0x14. C Bit manipulation Task 05 - humtej1204/holbertonschool-low_level_programming GitHub Wiki

5. 101

mandatory

Write a function that returns the number of bits you would need to flip to get from one number to another.

  • Prototype: unsigned int flip_bits(unsigned long int n, unsigned long int m);
  • You are not allowed to use the % or / operators
julien@ubuntu:~/0x14. Binary$ cat 5-main.c
#include <stdio.h>
#include "main.h"

/**
 * main - check the code
 *
 * Return: Always 0.
 */
int main(void)
{
    unsigned int n;

    n = flip_bits(1024, 1);
    printf("%u\n", n);
    n = flip_bits(402, 98);
    printf("%u\n", n);
    n = flip_bits(1024, 3);
    printf("%u\n", n);
    n = flip_bits(1024, 1025);
    printf("%u\n", n);
    return (0);
}
julien@ubuntu:~/0x14. Binary$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 5-main.c 5-flip_bits.c -o f
julien@ubuntu:~/0x14. Binary$ ./f
2
5
3
1
julien@ubuntu:~/0x14. Binary$ 

Repo:

  • GitHub repository: holbertonschool-low_level_programming
  • Directory: 0x14-bit_manipulation
  • File: 5-flip_bits.c
⚠️ **GitHub.com Fallback** ⚠️