Skip to content

Instantly share code, notes, and snippets.

@ryangraham
Created April 30, 2020 06:11
Show Gist options
  • Save ryangraham/70f0ee694c94b0af645c96590268e14d to your computer and use it in GitHub Desktop.
Save ryangraham/70f0ee694c94b0af645c96590268e14d to your computer and use it in GitHub Desktop.
to_lower
#include <string>
#include <iostream>
char to_upper(char c)
{
// between 97 and 122?
if (c >= 'a' && c <= 'z')
return c ^ 32; // unset 6th bit
return c;
}
char to_lower(char c)
{
// between 65 & 90?
if (c >= 'A' && c <= 'Z')
return c ^ 32; // set 6th bit
return c;
}
int main() {
std::string hexabet = "123456789ABCDEF";
for(char& c : hexabet)
std::cout << to_lower(c);
std::cout << std::endl;
std::cout << hexabet << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment