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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:02:37+00:00 2026-05-23T16:02:37+00:00

Here is a simple way to calculate an integer square root: int isqrt(int num)

  • 0

Here is a simple way to calculate an integer square root:

int isqrt(int num)
{
    int root=0;
    int b = 0x8000;
    int a=0, c=0;

    while (b) {
        c = a|b;

        if (c*c <= num)
            a |= b;   

        b >>= 1;
    }       
}

Ingeniously (thanks Wikipedia), this can be optimised like this:

int sqrt(short num)
{
    int op = num;
    int res = 0;
    int one = 1 << 30;

    while (one > op)
        one >>= 2;

    while (one != 0) {
        if (op >= res + one) {
            op -= res + one;
            res = (res >> 1) + one;
        }
        else
          res >>= 1;
        one >>= 2;
    }
    return res;
}

My question: Can a similarly optimised algorithm be written for an integer cube root? (This is to be run on a small microcontroller which prefers not to do multiplications)

  • 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-23T16:02:38+00:00Added an answer on May 23, 2026 at 4:02 pm

    According to this SO question and to the answer marked, from the Hacker’s Delight book you can find this implementation:

    int icbrt2(unsigned x) {
       int s;
       unsigned y, b, y2;
    
       y2 = 0;
       y = 0;
       for (s = 30; s >= 0; s = s - 3) {
          y2 = 4*y2;
          y = 2*y;
          b = (3*(y2 + y) + 1) << s;
          if (x >= b) {
             x = x - b;
             y2 = y2 + 2*y + 1;
             y = y + 1;
          }
       }
       return y;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple question here: is there any way to convert from a jagged array to
a simple question here Is there a way to change the text click here
What is the best way to implement simple pagination? Here is the code im
I'm probably missing something simple here, but I can't find the answer elsewhere. I
I am probably overlooking something really simple here but I am trying to redirect
Please excuse me if I'm simple here, I want to create a simple widget
No doubt I'm missing something really simple here but I just can't see the
I hope I am not missing something very simple here. I have done a
Here is some simple Perl to count the number of times a value occurs
Here's a simple (hopefully) L10N question: Do all locales want this format: Sunday, Nov

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.