Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

Program Discussion :: Bitwise Operator
Home > Programs > Bitwise Operator

13. Write an efficient program to set the bits in a given range(start and end position given) in an integer number

Answer:

import java.util.*;
import java.lang.*;
import java.io.*;

class SetBits
{
    public
      int start;
      int end;
      int num;


public
 SetBits(int s, int e, int n)
 {
     start = s;
    end = e;
    num = n;
 }

  void set()
  {
    for (int i = start; i<= end; i++)
      num = num | (1<<i);
  }
}
class ABC
{
 public static void main(String args[])
 {
  int start,end, num;
  Scanner in = new Scanner(System.in);

  System.out.println("Enter any number");
  num = in.nextInt();
  System.out.println("Enter starting position ");
  start = in.nextInt();
  System.out.println("Enter ending position ");
  end = in.nextInt();
     
  SetBits obj = new SetBits(start,end,num);
  obj.set();
  System.out.printf("number after bits set  "+obj.num);
 }
}

Post Your Answer Here:

Name *
Email

Language:

Post Your Reply Here:



Language:

Post Your Reply Here: