Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
antsim
/
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
9796a1c2
authored
Apr 10, 2017
by
antsim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pr10
parent
d5ad0e51
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
PR10/Lab10.c
PR10/Lab10.c
0 → 100644
View file @
9796a1c2
#include <stdio.h>
#include <string.h>
void
printBits
(
unsigned
int
num
);
int
main
()
{
unsigned
int
a
;
unsigned
int
b
;
int
c
=
0
;
int
nihe
=
0
;
int
menu
;
printf
(
"Enter option:
\n
"
);
printf
(
"1. Conjunction
\n
"
);
printf
(
"2. Disjunction
\n
"
);
printf
(
"3. Nihutamine vasakule
\n
"
);
printf
(
"3. Nihtamine paremale
\n
"
);
scanf
(
"%d"
,
&
menu
);
switch
(
menu
)
{
case
1
:
c
=
a
&
b
;
printf
(
"Enter the first numer a: "
);
scanf
(
"%u"
,
&
a
);
printf
(
"Enter the second number b: "
);
scanf
(
"%u"
,
&
b
);
printf
(
"%d Value in Bits: "
,
a
);
printBits
(
a
);
printf
(
"
\n
"
);
printf
(
"%d Value in Bits: "
,
b
);
printBits
(
b
);
printf
(
"Line a & b - Value of c is %d
\n
"
,
c
);
printBits
(
c
);
break
;
case
2
:
c
=
a
|
b
;
printf
(
"Enter the first numer a: "
);
scanf
(
"%u"
,
&
a
);
printf
(
"Enter the second number b: "
);
scanf
(
"%u"
,
&
b
);
printf
(
"%d Value in Bits: "
,
a
);
printBits
(
a
);
printf
(
"
\n
"
);
printf
(
"%d Value in Bits: "
,
b
);
printBits
(
b
);
printf
(
"Line a & b - Value of c is %d
\n
"
,
c
);
printBits
(
c
);
printf
(
"
\n
"
);
break
;
case
3
:
printf
(
"Sisestage nihe vaartus:"
);
scanf
(
"%d"
,
&
nihe
);
c
=
a
<<
nihe
;
printf
(
"Line a << %d - Value of c is %d
\n
"
,
nihe
,
c
);
printBits
(
c
);
printf
(
"
\n
"
);
break
;
case
4
:
printf
(
"Sisestage nihe vaartus:"
);
scanf
(
"%d"
,
&
nihe
);
c
=
a
>>
nihe
;
printf
(
"Line a >> %d - Value of c is %d
\n
"
,
nihe
,
c
);
printBits
(
c
);
printf
(
"
\n
"
);
break
;
default:
printf
(
"You have entered an invalid option
\n
"
);
}
return
0
;
}
void
printBits
(
unsigned
int
num
){
unsigned
int
size
=
sizeof
(
unsigned
int
);
unsigned
int
maxPow
=
1
<<
(
size
*
8
-
1
);
int
i
=
0
;
for
(;
i
<
size
*
8
;
++
i
){
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