Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
log base 2 calculation.
#1
How do I quickly calculate the log base 2 ceiling based on the number digit size and the first digit?

:???:

One thing I think is true is that it isn't a constant based on the length, but some sort of exponentiation...

This could go as a challenge perhaps...
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#2
The LOG base 2 of X (in QB) is LOG(X) / LOG(2), if that helps.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#3
Just a function that returns the ceiling log base 2 of x given the last digit of X and the amount of digits of X. "Ceiling log base 2" meaning "how many bits are required to store the number?"
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#4
integers. (I'm not sure anything else would be too meaningful.) I think the formula I just posted *would* help. If X is your integer, the number of bits it needs should be

NBITS = INT(LOG2(X)) + 1

In other words, it's the integer part of (log-base 2 of X) + one. And

LOG2(X) = LOG(X) / LOG(2)

(I'm still testing it out, but I think it works.)

Well, I can't get it to fail. Your turn to try. Smile
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#5
no, no. NO!!!!!!!!!!!! GLENNNNNN!!!!!!!!!!

function lg2(digit.number, first.digit)

lg2 = (somefunction(digit.number) someoperation somefunction first.digit))
end function

That's what I mean! NOT USING the QB LOG function!! THIS NUMBER WILL BE *HUGE*, like I dunno, a few hundred or possibly thousand digits!
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#6
representation, you want to know how many bits there are in the binary representation? 1) I can't image why you'd need to do that. 2) That doesn't matter. 3) I'm suspecting you're looking for something not real simple, not likely to occur, and I can't imagine an algorithm to do such a thing being real reliable. 4) I've been known to not have a good imagination.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#7
I guess I'll have to figure it out myself using analysis for a bunch of numbers.

What you need is the number of digits and the last number. Why?
Well......... because you multiply by two every time to get a different bit length....

So why do I need it? To calculate how large an array I need for my decimal > bit conversion. (I've started, but it has a Fatal Flaw that I realized a bit after doing it, which I'll fix soon..)
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#8
really help you, but the first one (on the left) would seem to be most useful. 10,000 requires 14 bits. 20,000 requires 15 bits. Does 19,000 reguire 14 bits, like 10,000? No, it requires 15 bits, like 20,000. Using the first two digits here might resolve the ambiguity. However, larger numbers might require looking at even more than that. At any rate, if N is the number of digits, a really crude, not very reliable formula you could try is

NBITS = INT(N * LOG(10) / LOG(2)) + 1

It's not real accurate and is most likely to give you an over-estimate. It's no substitute for just taking the log-base 2.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#9
hm... ok.. on a path in the right direction now.....
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#10
That formula is just a fuzzy derivation based on the concept of using the log-base 2 to find the exact number of digits. Smile
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)