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 9161197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:54:51+00:00 2026-06-17T13:54:51+00:00

If I have a number greater than 20 but that can be divided evenly

  • 0

If I have a number greater than 20 but that can be divided evenly by 2 without any remainder, I want to determine what number gets me closest to 20. For example:

For 2048, dividing by 2 enough times would get me to 16 which is the closest I can get to 20. If the number is 800, the closest is 25.

I can write a loop and just keep dividing and comparing the range and pick the value that is closest. Is there maybe a simpler way, possibly through shifting bits?

EDIT: When I say it evenly divides by 2, I mean it divides all the way down to 2 as well. A number of 70 would only divide down to 35 evenly. A number like 2048 or 1024 will divide evenly all the way to 2.

Sample numbers: 2048, 1920, 1600, 1536, 1080..640, 352, 320, 176. These are typical image sizes from cameras.

  • 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-17T13:54:52+00:00Added an answer on June 17, 2026 at 1:54 pm

    If your input number is x, I think you want x/2^[(log x/14)/log 2], assuming you want your target number to be in the interval [14,27].

    In java code, Math‘s log function will come in handy (although base-2 logarithm would be even better), and you also need an integer cast (or somehow find the largest integer smaller than the expression in []).

    What this does: Let x be your input and y be the number you want to find. Then, x=y*2^n for yet unknown n, while y is around 20 (see above). Obviously, n is the base-2 logarithm of x/y. Now, if you pick the smallest possible y, call it y', the integer part of the base-2 logarithm of x/y' is still the n we are looking for, unless x/y' differs from x/y by a factor of more than 2, which by assumption of repeated division by 2 it cannot. Thus, we have n and hence y=x/2^n.

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

Sidebar

Related Questions

I have number of line breaks in a string. But I only want it
I have a number of draggable images that I want to clone and then
I have a Maven archtype that use a requiredProperty that contains a number, but
I have a table with a variable number of columns that I want to
Let's suppose I have n arrays, where n is a variable (some number greater
I'm stuck with the following scenario and appreciate any help/advice.. Requirement I have number
I have a number input that should trigger jQuery on every change. To do
We have a number of data objects that realize INotifyPropertyChanged to allow for WPF
I have a number of classes (more than 40), each one has a number
I have a number of text input elements that when its values are changed,

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.