Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
basic operations task2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
elijah vasquez
basic operations task2
Commits
5b1e3d42
Commit
5b1e3d42
authored
Sep 28, 2022
by
elijah vasquez
🦍
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit now hahah
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
main.c
main.c
+52
-0
No files found.
main.c
0 → 100644
View file @
5b1e3d42
##include <string.h>
##include <stdio.h>
/* Print binary stored in plain 32 bit block */
void
intToBinary
(
unsigned
int
n
)
{
int
c
,
k
,
i
;
printf
(
"How the number is stored in memory "
);
for
(
c
=
31
;
c
>=
0
;
c
--
)
{
k
=
n
>>
c
;
// k = n dividedby 2 c times
// or
// take the binary representation of k and move all the digits to the right c times
// since the loop c starts at 31 the first round of the loop moves the left most bit to the units column ( and rottes the rest round)
// we can then use a bitwise and (&) command to compare the righmost digit (previously the leftmost) to 000000000001
// if (k & 1) is true then that bit is 1 otherwise it is zero
// we can then move on to the next loop and look at the second leftmost and so on.
if
(
k
&
1
)
printf
(
"1"
);
else
printf
(
"0"
);
}
printf
(
" X * 2 ^ Y
\n
"
);
}
int
main
(
void
)
{
unsigned
int
m
;
float
f
=
3
.
14
;
printf
(
"
\n\n\n
f = %f
\n
"
,
f
);
/* See hex representation */
printf
(
"Float Point Representation of f = %a"
,
f
);
printf
(
" hexadecimal X * 16 ^ Y
\n
"
);
/* Copy memory representation of float to plain 32 bit block */
memcpy
(
&
m
,
&
f
,
sizeof
(
m
));
intToBinary
(
m
);
printf
(
"
\n\n\n
"
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment