Skip to main content

Posts

Showing posts from March, 2019

How to solve print_bits on the 42 Exam

How to solve print_bits on the 42 Exam This is a walkthrough of how to do the print_bits assignment for the 42 exam. Assignment name : print_bits Expected files : print_bits.c Allowed functions: write -------------------------------------------------------------------------------- Write a function that takes a byte, and prints it in binary WITHOUT A NEWLINE AT THE END. Your function must be declared as follows: void print_bits(unsigned char octet); Example, if you pass 2 to print_bits, it will print "00000010" 1.) Make sure you have a good understanding of bits and bytes with the video above. 2.) Then you need to understand bit shifting. It’s a simple concept and Jamie Dawson has a great short tutorial on it here: Basic Bit Shifting Guide 3.) Understanding Bitwise Operators: I found the Swift guide on bitwise operators to be the best. https://docs.swift.org/swift-book/LanguageGuide/AdvancedOperators.html 4.) Solving Print Bits // solu