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

4. 100

mandatory

Write a function that sets the value of a bit to 0 at a given index.

  • Prototype: int clear_bit(unsigned long int *n, unsigned int index);
  • where index is the index, starting from 0 of the bit you want to set
  • Returns: 1 if it worked, or -1 if an error occurred
julien@ubuntu:~/0x14. Binary$ cat 4-main.c
#include <stdio.h>
#include "main.h"

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

    n = 1024;
    clear_bit(&n, 10);
    printf("%lu\n", n);
    n = 0;
    clear_bit(&n, 10);
    printf("%lu\n", n);
    n = 98;
    clear_bit(&n, 1);
    printf("%lu\n", n);
    return (0);
}
julien@ubuntu:~/0x14. Binary$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 4-main.c 4-clear_bit.c -o e
julien@ubuntu:~/0x14. Binary$ ./e
0
0
96
julien@ubuntu:~/0x14. Binary$ 

Repo:

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