Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSE 13S demos Spring 2022
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alex Rudnick
CSE 13S demos Spring 2022
Commits
55c4e3dd
Commit
55c4e3dd
authored
2 years ago
by
Alex Rudnick
Browse files
Options
Downloads
Patches
Plain Diff
some demos from class, should have checked in earlier
parent
6a37ae25
Branches
master
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bitwise/bitwise.c
+49
-0
49 additions, 0 deletions
bitwise/bitwise.c
regex/regex.c
+21
-0
21 additions, 0 deletions
regex/regex.c
with
70 additions
and
0 deletions
bitwise/bitwise.c
0 → 100644
+
49
−
0
View file @
55c4e3dd
#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
;
}
This diff is collapsed.
Click to expand it.
regex/regex.c
0 → 100644
+
21
−
0
View file @
55c4e3dd
#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
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment