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

  • SEARCH
  • Home
  • 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 8541537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:51:19+00:00 2026-06-11T11:51:19+00:00

I am wondering if there is a short way (without programming the whole thing)

  • 0

I am wondering if there is a short way (without programming the whole thing) of determining the largest number in a binary value in T-SQL.

In a column I store what days are selected (1 = sunday, 2 = monday, .. 7 = saturday) bitwise.

My translation table:

-- day of week
-- 1 == 1       -> POWER(2,0) -> sunday
-- 2 == 2       -> POWER(2,1) -> monday
-- 3 == 4       -> POWER(2,2)
-- 4 == 8       -> POWER(2,3)
-- 5 == 16      -> POWER(2,4)
-- 6 == 32      -> POWER(2,5)
-- 7 == 64      -> POWER(2,6) -> saturday

So if I select FOR EXAMPLE sunday and saturday my binary value is 65.

How can I select with T-SQL that 65 will be 7??


Edit

Lets say I have two record with a two columns:

 ID   | SelectedDays 
------|--------------
 1    | 65
 2    | 3

So, ID 1 will return 7, because that will be the saturday that is selected selected and ID 2 will return monday.

  • 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-06-11T11:51:21+00:00Added an answer on June 11, 2026 at 11:51 am
     SELECT FLOOR(LOG(bit_week)/LOG(2))+1
    

    This returns 1 to 7 depending of the date.
    logaritm is the inverse of power to obtanin logaritm in base 2, the trick is ‘divide by the base’. FLOOR, in its turn, provides the most significative bit.

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

Sidebar

Related Questions

just wondering if there is any way of checking if Value A is equal
In short, I am wondering if there is an auto_ptr like type for arrays.
Wondering if there is any way to get the lambda expressions that result from
Wondering if there is a good way to generate temporary URLs that expire in
just wondering if there is a way to reduce the amount of code needed
Just wondering is there any way I can check whether the url links to
Just wondering if there is any way to get the NS records in C#.
I'm wondering if there's a short notation in PHP for getting an object field
I was wondering that is there any way to run application made in visual
I was wondering if there exists a way to run an untrusted C program

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.