Skip to content

Latest commit

 

History

History
141 lines (93 loc) · 4.2 KB

File metadata and controls

141 lines (93 loc) · 4.2 KB

0x14. C - Bit manipulation

Resources

Read or watch:

Learning Objectives

General

  • Look for the right source of information without too much help
  • How to manipulate bits and use bitwise operators

Tasks

0. 0

  • Write a function that converts a binary number to an unsigned int.

Requirements:

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


1. 1

  • Write a function that prints the binary representation of a number.

Requirements:

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


2. 10

  • Write a function that returns the value of a bit at a given index.

Requirements:

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


3. 11

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

Requirements:

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


4. 100

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

Requirements:

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


5. 101

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

Requirements:

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


6. Endianness

  • Write a function that checks the endianness.

Requirements:

Prototype: int get_endianness(void); Returns: 0 if big endian, 1 if little endian

Mode: #advanced

File: 100-get_endianness.c


7. Crackme3

  • Find the password for this program.

Requirements:

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