- Operators in C - Part 6
- Operators in C - Part 7 (Bitwise Operators-II)
- Bitwise Operators 1: The AND Operation
- Bitwise Operators 2: The OR Operation
- Bitwise Operators 3: The XOR Operation
- Bitwise Operators 4: The Logical Shift Operation
- Bit Manipulation
- Bitwise Operators
- Youtube
- Look for the right source of information without too much help
- How to manipulate bits and use bitwise operators
- Write a function that converts a binary number to an unsigned int.
Prototype: unsigned int binary_to_uint(const char *b);
where b
is pointing to a string of 0
and 1
chars
Return: the converted number, or 0 if
there is one or more chars in the string b that is not 0 or 1 b is NULL
there is one or more chars in the string b
that is not 0
or 1
b
is NULL
Mode: mandatory
File: 0-binary_to_uint.c
- Write a function that prints the binary representation of a number.
Prototype: void print_binary(unsigned long int n);
Format: see example
You are not allowed to use arrays
You are not allowed to use malloc
You are not allowed to use the %
or /
operators
Mode: mandatory
File: 1-print_binary.c
- Write a function that returns the value of a bit at a given index.
Prototype: int get_bit(unsigned long int n, unsigned int index);
where index
is the index, starting from 0
of the bit you want to get
Returns: the value of the bit at index index
or -1
if an error occured
Mode: mandatory
File: 2-get_bit.c
- Write a function that sets the value of a bit to 1 at a given index.
Prototype: int set_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
Mode: mandatory
File: 3-set_bit.c
- 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
Mode: mandatory
File: 4-clear_bit.c
- 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
Mode: mandatory
File: 5-flip_bits.c
- Write a function that checks the endianness.
Prototype: int get_endianness(void);
Returns: 0
if big endian, 1
if little endian
Mode: #advanced
File: 100-get_endianness.c
- Find the password for this program.
Save the password in the file 101-password
Your file should contain the exact password, no new line, no extra space
Mode: #advanced
File: 101-password