Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Raul.Leemet
/
IAG0582
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0df225ba
authored
Apr 05, 2017
by
Raul.Leemet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload new file
parent
81763daf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
Praktikum10/tund.c
Praktikum10/tund.c
0 → 100644
View file @
0df225ba
#include <stdio.h>
void
printBits
(
unsigned
int
num
);
int
main
()
{
unsigned
int
a
=
60
;
/* 60 = 0011 1100 */
unsigned
int
b
=
13
;
/* 13 = 0000 1101 */
int
c
=
0
;
printf
(
"%d Value in Bits: "
,
a
);
printBits
(
a
);
printf
(
"
\n
"
);
printf
(
"%d Value in Bits: "
,
b
);
printBits
(
b
);
printf
(
"
\n
"
);
c
=
a
&
b
;
/* 12 = 0000 1100 */
printf
(
"Line a & b - Value of c is %d
\n
"
,
c
);
printBits
(
c
);
printf
(
"
\n
"
);
c
=
a
|
b
;
/* 61 = 0011 1101 */
printf
(
"Line a | b - Value of c is %d
\n
"
,
c
);
printBits
(
c
);
printf
(
"
\n
"
);
c
=
a
^
b
;
/* 49 = 0011 0001 */
printf
(
"Line a ^ b - Value of c is %d
\n
"
,
c
);
printBits
(
c
);
printf
(
"
\n
"
);
c
=
~
a
;
/*-61 = 1100 0011 */
printf
(
"Line ~a - Value of c is %d
\n
"
,
c
);
printBits
(
c
);
printf
(
"
\n
"
);
c
=
a
<<
2
;
/* 240 = 1111 0000 */
printf
(
"Line a << 2 - Value of c is %d
\n
"
,
c
);
printBits
(
c
);
printf
(
"
\n
"
);
c
=
a
>>
2
;
/* 15 = 0000 1111 */
printf
(
"Line a >> 2 - Value of c is %d
\n
"
,
c
);
printBits
(
c
);
printf
(
"
\n
"
);
return
0
;
}
void
printBits
(
unsigned
int
num
){
unsigned
int
size
=
sizeof
(
unsigned
int
);
unsigned
int
maxPow
=
1
<<
(
size
*
8
-
1
);
// printf("MAX POW : %u\n",maxPow);
int
i
=
0
,
j
;
for
(;
i
<
size
*
8
;
++
i
){
// print last bit and shift left.
printf
(
"%u "
,
!!
(
num
&
maxPow
));
num
=
num
<<
1
;
}
}
/*
*/
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