Skip to content

Instantly share code, notes, and snippets.

@andrija-zikovic
Created May 26, 2023 10:54
Show Gist options
  • Save andrija-zikovic/6857bc97407c63b2a206e2ec35fa4d32 to your computer and use it in GitHub Desktop.
Save andrija-zikovic/6857bc97407c63b2a206e2ec35fa4d32 to your computer and use it in GitHub Desktop.
CS50/bulbs
#include <cs50.h>
#include <stdio.h>
#include <string.h>
const int BITS_IN_BYTE = 8;
void print_bulb(int bit);
int main(void)
{
// TODO
string text = get_string("Message: \n");
for (int i = 0; text[i]!='\0'; ++i)
{
int text_to_bit[BITS_IN_BYTE] = {};
int decimal = text[i];
int j = 0;
while (decimal > 0)
{
text_to_bit[j] = decimal % 2;
decimal = decimal / 2;
j++;
}
for (int k = BITS_IN_BYTE - 1; k >= 0; k--)
{
print_bulb(text_to_bit[k]);
}
printf("\n");
}
}
void print_bulb(int bit)
{
if (bit == 0)
{
// Dark emoji
printf("\U000026AB");
}
else if (bit == 1)
{
// Light emoji
printf("\U0001F7E1");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment