Counting Bits in an Integer

During a tech screen I was given the task of writing a function to count the number of bits in an integer given. I thought I’d share what I came up with.

#include <stdio.h>

int count_bits(int i) {
    int bit_count = 0;
    int comparator = 0x1;

    for (int x = 0; x < sizeof(int) * 8; x++) {
        if (comparator & i) {

        comparitor <<= 1;

    return bit_count;

int main(int argc, char *argv[]) {
    // 1
    printf("%dn", count_bits(1));
    // 2
    printf("%dn", count_bits(3));
    // 4
    printf("%dn", count_bits(0x00011101));
    return 0;

I don’t know if there’s a better way to do this, but what I did create a comparator with 1 bit (0x1), loop through the number of bits in an int (sizeof(int)*8), do a bitwise AND to see if that bit is flipped in the int I’m counting against, and then shift left one and do it again.

Putting Code on Dropbox

On the latest episode of Under the Radar, David mentioned that he stores all of his code in Dropbox, rather than pushing and pulling to a Git repo to sync between his machines. Of course, he’s not an animal, so he also uses Git, just not for syncing between his personal machines.

I’ve never done this but once he said it, I was pretty much convinced and moved all of my code to a folder on Dropbox. Why wouldn’t I want the current state of my work, including what branches I was working on locally that I haven’t necessarily pushed to GitHub to be kept in sync so everything I need to work is automatically wherever I am?

In fact, if I’m just working by myself on a project by myself, I don’t even need to push it to GitHub at all until I want to share it with someone else in order to get the benefits of having my code backed up externally and kept in sync across my machines?

Am I crazy, missing something, or was everyone else already doing this?

If Object-Oriented Programming Were Announced Today

Graham Lee has a post titled If Object-Oriented Programming were announced today:

Here’s an idea: the current backlash against OOP is actually because people aren’t doing OOP, they’re doing whatever they were doing before OOP. But they’re calling it OOP, because the people who were promoting OOP wanted them to believe that they were already doing OOP.

Basically, Graham argues that a lot of the “newer” paradigms are just OOP by a different name, and that none of us were really doing pure OOP to begin with. You should also check out his talk at UlKonf 2015Object Oriented Programming in Objective-C — where he talks about a lot of the same things in greater detail.

Up First by NPR

The Up First podcast from NPR is a morning briefing show that’s about ten minutes long; meant to catch you up on the most important news of the previous day. I’ve just started listening to it after having it recommended to me, and think it’s great. The episodes are the perfect length to listen to in the shower and pretty information dense.

Hire Me

If you’re looking to hire an iOS developer with over nine years of professional experience for contracting or full time employment, I am now available for either of those things with immediate effect.

Email me at my full name at gmail dot com if you’re interested.

How to Sound Good on a Podcast

If you read this blog, you know that I do a weekly interview podcast called The Run Loop. The show (generally) has remote guests with different audio setups and level of comfort in front of a microphone, so I wanted to write a short tutorial I could send to future guests to prepare them to be on the show and get the best audio quality. I then realized it made a lot more sense to make that a blog post so that other people could use it as a resource as well. So, here it is. Following this should help anyone sound good on a podcast regardless of previous experience.

Getting a Microphone

If you already have a microphone you can use for recording, great! A lot of people have a Blue Yeti, which can give you pretty good sound quality if you’ve got a good environment, or a Rode Podcaster which is really easy to set up for beginners to get a good enough sound. If you already have one of those two, great. I’m going to tell you how to get the best audio quality out of them. Otherwise, I’m going to tell you what to buy and how to use it. If you don’t, and you are preparing to be on a podcast, the one I’m going to recommend is the Audio Technica ATR2100 . You’ll also want to get one of these windscreens for it to block out plosives (p sounds) and a stand for it. This stand attaches to your desk. All together you’re looking at about $85.

Why do I recommend the ATR2100? A few reasons. First, it’s a dynamic cardioid microphone. Dynamic means it’s going to be more forgiving to an untreated room than what’s called a condenser microphone. It’s not important the differences between the two types of microphone, but generally speaking, a condenser is going to pick up a lot more (mouth sounds, cars outside, room echo, etc). That’s great if you’re recording an acoustic guitar or in a professional recording setting, but not so much for a beginning podcaster. The Yeti is a condenser. The ATR2100 is a dynamic. Cardioid means it’s going to pick up mostly what’s in front of it and not other directions.

Secondly, it’s a USB mic, but it also has an XLR plug. XLR is what “professional” audio interfaces and microphones use. So if you decide you want to graduate to a standalone audio interface or you need a mic that can plug into a mixer or whatever, you have room to grow.

The last reason is that it sounds really good for a $70 mic. If you want to hear an example of this, listen to this episode of The Run Loop with Laura Savino. She used the ATR2100 and required very little editing or tweaking to make sound good.


You’re also going to want a set of headphones. In a pinch, anything will do, but ideally, you want some big over the ear headphones that block out external sound. If you already have something that fits that description you should be okay, but if you want to get some recording specific headphones, these Sony ones are great for about $100. I haven’t used these $40 Sennheiser ones, but they look like they would be good and I’ve seen them recommended elsewhere.

You’ll want to plug them directly into your microphone/interface for low-latency monitoring of your own voice. It’s important to hear yourself so that you don’t drift away from the microphone without realizing it. When you’re recording, keep it at a comfortable, but not too loud volume, or even with closed headphones you’ll get some bleed from the people you’re talking with.

Setting Levels

If your microphone/interface doesn’t have a knob for setting levels, you’re set. The Rode Podcaster is like this. If it does, you need to turn up the level on your microphone to get a good signal. Load up GarageBand, create a new audio track, and select your microphone as the input. Now talk into it at a normal speaking volume and adjust the gain knob on your microphone. If you look at the track volume indicator, you want it to be averaging in about the 40-50% range on that slider (-15 to -12 dBFS if you’re using a different app that shows you the numbers). The reason you want it to be in this range is to give yourself what’s called headroom. If you go above 0 dB, you’re going to clip and distort the recording.

If you’ve been around audio at all, you might have heard that you want to peak around 0 dB. The reason for that is that on analog gear, it wouldn’t actually distort until something like +18 dB, so at 0 dB you still had a bunch of headroom. On digital gear you will distort at 0, so recording at around -12 to -15 is the same as recording at 0 on analog gear.

Preparing Your Environment

Before you go on the podcast, you should record some tests with your mic in the room you’ll be recording in. Put on your headphones, turn up the volume, and listen to your room through your mic. Everything you hear is going to come through on the recording. Turn off fans, air conditioning, anything like that which is getting picked up. I turn off my refrigerator when I record.

Now, get close to your microphone (2-4”), hit record, and speak into it. What does it sound like? If you’re getting echo, try hanging a blanket behind the mic to catch some of those reflections.

If you hear electronic interference, you’re going to need to get rid of that. Often, it’s some kind of grounding or power issue. Try changing what your computer is plugged into. If you’re on a laptop and using the two prong adapter, try the three prong one, or vice versa. If you’re plugged in, try recording on battery and see if it goes away. If all else fails, do a Google search.

Mic Technique

If you’re looking for a video on what good mic technique looks like, this video by Dan Benjamin will show you.

If you’re wondering how far you should be away from your microphone and what looks like, my tip is this: put your four fingers together minus your thumb like a karate chop. Put your pinky on the microphone, and place your lips on your index finger. Now stay exactly there. If you move left, right, forward, or backwards, the sound is going to suffer.

The other important thing to remember is that anything that happens in front of the mic is going to get picked up. If you scratch your face while talking, that’s going to show up on the recording, and there’s no way to remove it later. Same for bumping your desk, fiddling with your AirPods case, etc.

Wrap Up

This probably all sounds like a lot to adsorb, and it is, but if you can follow it, you’re going to sound way better than most people who go on a podcast. The main points to keep in mind are:

  • Get a microphone that’s forgiving and sounds good. I recommend this one.
  • Set your levels properly.
  • Get rid of as much room noise as you can.
  • Talk directly into the mic.
  • Don’t make any noise you don’t want to be recorded.

I hope this all helps, and if you have any other questions, please get in touch via Twitter.

Going to PodCon

I’m going to be attending PodCon in Seattle December 9-10, 2017:

We even love podcasts we’ve never heard because we kinda like the entire idea of podcasts. Which is why we want to create an event that celebrates this medium/art form/whatever it is. We’re bringing together a diverse group of podcast pros in Seattle, Washington for two days of live podcasts, performances, discussions, workshops, and weirdness.

It’s going to have awesome people like Roman Mars, Dylan Marron of Welcome to Night Vale, the McElroy brothers, and a bunch of other podcasters who I haven’t listened to but will definitely look up before I go. Tickets are cheap (~$100). If you can make it, you should come and let me know you are.

Laura Savino on The Run Loop

On the latest episode of The Run Loop, Laura Savino comes on the show to talk about natural vs computer languages, decipherable and readable code, and a lot more. Go check it out.

For the audio nerds out there, Laura was using an Audio Technica ATR2100 dynamic USB microphone, and I can’t believe how good this mic sounds for $70. If you’re getting started in podcasting and don’t want to spend a ton of money, I’d recommend this one super highly.