Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7532261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:24:01+00:00 2026-05-30T05:24:01+00:00

I am using bitwise operation to store availability with 1 bit representing one minutes.

  • 0

I am using bitwise operation to store availability with 1 bit representing one minutes. So one day of availability can be represented by 1 long (8 bytes so 60 bits out of 64 bits) can be used to represent 1 hour so 24 longs will represent availability per day.

Now I have a range of times (ex. 2:00 – 4:00, 15:00 to 17:00) and I need to translate this into bit mask to compare against above longs of availabilities to see if the ranges in the mask is available or unavailable (& with mask) what is the best way to translate this range of times to bits?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:24:02+00:00Added an answer on May 30, 2026 at 5:24 am

    I think this works:

    private static int getMinuteOfDay(Date date) {
        Calendar cal = new GregorianCalendar();
    
        cal.setTime(date);
    
        return cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE);
    }
    
    private static void addAvailability(Date startTime, Date endTime, BitSet bs) {
    
        int startMinute = getMinuteOfDay(startTime);
        int endMinute = getMinuteOfDay(endTime);
    
        bs.set(startMinute, endMinute);
    }
    
    private static boolean timeIsAvailable(Date time, BitSet bs) {
        return bs.get(getMinuteOfDay(time));
    }
    
    static DateFormat TIME_FORMAT = new SimpleDateFormat("HH:MM:ss");
    
    public static void main(String[] args) {
        BitSet availability = new BitSet();
    
        try {
            addAvailability(TIME_FORMAT.parse("02:00:00"), TIME_FORMAT.parse("04:00:00"), availability);
            addAvailability(TIME_FORMAT.parse("15:00:00"), TIME_FORMAT.parse("17:00:00"), availability);
    
            System.out.println(timeIsAvailable(TIME_FORMAT.parse("01:19:00"), availability));
            System.out.println(timeIsAvailable(TIME_FORMAT.parse("02:00:00"), availability));
            System.out.println(timeIsAvailable(TIME_FORMAT.parse("02:01:00"), availability));
            System.out.println(timeIsAvailable(TIME_FORMAT.parse("04:00:00"), availability));
            System.out.println(timeIsAvailable(TIME_FORMAT.parse("04:01:00"), availability));
            System.out.println(timeIsAvailable(TIME_FORMAT.parse("16:00:00"), availability));
            System.out.println(timeIsAvailable(TIME_FORMAT.parse("17:10:00"), availability));
    
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    
    }
    

    Results:

    false
    true
    true
    false
    false
    true
    false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can the XOR operation (on two 32 bit ints) be implemented using only
In Java, is it possible to clear a bit using bitwise operations?
For a particular application using bitwise masks to store a value, I'd like to
I am new to using the PARI C library. How can I perform bitwise
I had an idea to store hour-by-hour availability using a binary string that I
How is the conditional operator represented using bitwise operators? It is a homework question
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
How can I implement the rightrotate (and leftrotate) operations on 32 bit integers without
I would like to store all currently-pressed keycodes in a single variable by using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.