0% found this document useful (0 votes)
5 views2 pages

Lecture4 BitWiseOperation

Uploaded by

nadesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Lecture4 BitWiseOperation

Uploaded by

nadesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Reg. No.

:
Name:

School of Electrical Engineering (SELECT), VIT Chennai


Lecture 4 - Assignment
Programme : B.Tech Electrical and Electronics Engineering Semester : Winter 2024-25
Course Code - Course Title : BCSE103E - Computer Programming : Java Max. Marks : 10

Topics : Binary Operations in Java


Course Outcome 1a : Understand basic programming constructs;
1. Task to be Done : Write the java code to do the following (3)
(a) Request the user to enter a Byte Number.
(b) Request the user to Enter the bit number that needs to be SET(1).
(c) Check if the particular bit is SET(1) or RESET(0) and inform the user.
(d) If the particular bit is RESET(0), SET(1) the particular bit.
(e) Execute your code / code given and give the byte Number = 54. Check and SET BIT 3. Give the
step wise result for the following lines
(i) Lines 16, 17, 19, 22,30
(f) Execute your code / code given and give the byte Number = 130. Check and SET BIT 3. Explain
the results got
1
2 import java . util . Scanner ;
3
4 public c l a s s BitSet
5 {
6
7 public s t a t i c void main ( String [] args )
8 {
9 byte num ;
10 byte bitNum ;
11 Scanner input = new Scanner ( System . in );
12 System . out . printf ( " Enter the integer Number : " );
13 num = input . nextByte ();
14 System . out . printf ( " Enter the Bit Number ( B0 to B7 ) you need SET (0 to 7) :
" );
15 bitNum = input . nextByte ();
16 byte checker = 1;
17 checker = (byte )( checker << bitNum );
18
19 i f (( num & checker ) == 0)
20 {
21 System . out . println ( " The B3 bit is RESET (0) position " );
22 num = (byte )( num | checker );
23 System . out . printf ( " The new value of Number = % d \ n " , num );
24
25 }
26 else
27 {
28 System . out . println ( " The B3 bit is already SET " );
29 }
30 input . close ();
31 }
32 }

Bit Set Java Code

Page 1 of 2
2. Task to be Done : Write the java code to do the following. Explain the binary operations you do to (5)
reach the goal.
(a) Request the user to enter a Byte Number.
(b) Request the user to Enter the bit number that needs to be RESET(0).
(c) Check if the particular bit is SET(1) or RESET(0) and inform the user.
(d) If the particular bit is SET(1),RESET(0) the particular bit.
3. Write the java code to take two byte inputs from the user and do the bitwise exclusive OR operation (2)
and print the result.

Question: 1 2 3 Total
Points: 3 5 2 10
Score:

⇔⇔⇔

Page 2 of 2

You might also like