[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to mathematically find out how many digits a number contain?

Posted on 2006-10-25
10
Medium Priority
?
326 Views
Last Modified: 2008-02-01
Hello. I have another question. How to mathematically find out how many digits a number contain?
0
Comment
Question by:m-jansen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17805796
floor(log(number)/log(10))
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17805805
Hi m-jansen,

Keep dividing the number by increasing powers of 10 until you get quotient 0

div = 10
count =1
while (num/div)
{
     div = div * 10
     count = count +1
}

Cheers!
sunnycoder
0
 
LVL 84

Accepted Solution

by:
ozo earned 750 total points
ID: 17805831
floor(1+log(floor(number)+.9)/log(10))
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:m-jansen
ID: 17805960
looks like
floor(1+log(number))
gave me the number of digits too... is that right?
0
 
LVL 39

Expert Comment

by:Adam314
ID: 17806206
If your log function assumes base 10.  The /log(10) takes care of when log doesn't use base 10.
0
 
LVL 22

Expert Comment

by:grg99
ID: 17806755
I guess it depends how accurate you need the answer to be, and the consequences of a possible off-by-one or two or three or six error.

Also you may not really want this.  For example,  this is the wrong way to calculate how much space you'll need to store the number as text.

If you could explain what you're trying to do maybe we can come up with the best answer.

0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 17806885
Negative numbers.
Decimals.
0
 

Author Comment

by:m-jansen
ID: 17806931
I am trying to get the length of an integer in VHDL.
0
 

Author Comment

by:m-jansen
ID: 17806943
...the number of digits in an VHDL integer
0
 

Author Comment

by:m-jansen
ID: 17807601
I think ozo answer is good enough. Thanks.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We are taking giant steps in technological advances in the field of wireless telephony. At just 10 years since the advent of smartphones, it is crucial to examine the benefits and disadvantages that have been report to us.
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question