473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

formula for logarithms to base two of a number

51
Is there a formula for finding logarithms to base two of a number.If so wtat is it.Thanks for any replying.
Mar 16 '09 #1
3 3801
Dormilich
8,658 Expert Mod 8TB
you mean if you don't have a calculator at hand that computes the logarithms?

there are some series you can use.
Mar 17 '09 #2
JosAH
11,448 Expert 8TB
There's a simple integer approximation:

Expand|Select|Wrap|Line Numbers
  1. int log2(unsigned int n) {
  2.   int log = 0;
  3.   if (n >= 1<<16) { n >>= 16; log += 16; }
  4.   if (n >= 1<< 8) { n >>=  8; log +=  8; }
  5.   if (n >= 1<< 4) { n >>=  4; log +=  4; }
  6.   if (n >= 1<< 2) { n >>=  2; log +=  2; }
  7.   if (n >= 1<< 1) {           log +=  1; }
  8.   return ((n == 0) ? -1 : log);
  9. }
  10.  
(this assumes C or C++ being used).

kind regards,

Jos
Mar 17 '09 #3
dynamo
51
thanks for replying.really appreciate it
Mar 22 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Konstantin Loguinov | last post by:
Guys, Here is my sample ASP code <% response.write log(2.63852242744063E-03) %> It shows -5.93753620508243 for result.
2
by: cowboyboborton | last post by:
Looking for some help here. I've tried to solve this, but I just can't. What I need to know is what formula to use in an excel calculation to complete the following calculation. It's in two...
4
by: David Dvali | last post by:
Hello. How can I generate some fixed length unique number (for example 6 character) based on some number like 1, 2, .. 45, 46, 47 (Generally I will use unique ID of the database record as base...
19
by: Robbie Hatley | last post by:
For your enjoyment, a function that expresses any integer with absolute value less-than-or-equal-to nine quintillion in any base from 2 to 36. (For larger bases, you could expand the "digit"...
11
by: jyck91 | last post by:
// Base Conversion // Aim: This program is to convert an inputted number // from base M into base N. Display the converted // number in base N. #include <stdio.h> #include <stdlib.h>...
7
by: MarkJ | last post by:
him im kinda new to c-sharp... to reference up the class chain, how do i reference the super class (parent) example class mybase { protected int abc=0 } classs myclass:mybase {
15
by: Lyosha | last post by:
Converting binary to base 10 is easy: 255 Converting base 10 number to hex or octal is easy: '0144' '0x64' Is there an *easy* way to convert a number to binary?
0
by: gkinu | last post by:
Crystal Report for Visual Studio.NET 2003. I have a formula that brings an error " .. A number is required here ... ". See the code snippet below which i have simplified. In the actual formula,...
2
by: Arthur Dent | last post by:
Hi all... I'm playing around experimenting with Extensions and R&D'ing what's new. There's a procedure I would like to add to numbers, and I was wondering, is there any "base" number type,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.