Skip to content
Snippets Groups Projects
Commit 55c4e3dd authored by Alex Rudnick's avatar Alex Rudnick
Browse files

some demos from class, should have checked in earlier

parent 6a37ae25
Branches master
No related tags found
No related merge requests found
#include <stdio.h>
void print_byte(unsigned char b) {
for (int shift=7; shift >=0; shift--) {
// xxxxxxxx &
// 10000000
// x0000000 --> 0000000x
// we call this "masking"
printf("%d", (b & (1 << shift)) >> shift);
}
printf("\n");
}
int main(void) {
// high four bits are set
// 11110000
unsigned char number_a = 0xF0;
// biggest number you can represent in the lower nibble of a byte; low four
// bits are set.
// 00001111
unsigned char number_b = 0x0F;
// 11110000 &
// 00001111
// 00000000
printf("%d\n", (number_a & number_b));
// 11110000 |
// 00001111
// 00000000
printf("%d\n", (number_a | number_b));
print_byte(number_a);
print_byte(~number_a);
print_byte(number_b);
printf("%d\n", (unsigned char)~number_a);
// printf("%d\n", number_b);
printf("%d\n", (unsigned char)(~number_a) == number_b);
// print_byte(0);
//print_byte(7);
return 0;
}
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>
int main(void) {
regex_t reg;
regcomp(&reg, "^..b.m$", 0);
int result = regexec(&reg, "album", 0, NULL, 0);
printf("what was the result? 0 for success: %d\n", result);
result = regexec(&reg, "something that doesn't contain the pattern", 0, NULL, 0);
printf("what was the result? 0 for success: %d\n", result);
result = regexec(&reg, "album of the year", 0, NULL, 0);
printf("what was the result? 0 for success: %d\n", result);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment