Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 06-08-2004, 07:56 AM   #1
Dusen
Confirmed User
 
Join Date: Aug 2002
Location: East Coast.
Posts: 2,251
Programming Problem - Help

I'm doing somethere where a selected value HAS to be an integer power of 2. Anyone know a "clean" way I could round a desired value to the nearest power of 2?

I.e. input is 37 -> rounded to 32

input is 84 - > rounded to 64

input is 99 -> rounded to 128


Just a general algo is fine, i can adapt it to PHP.
Dusen is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2004, 08:20 AM   #2
blazin
Confirmed User
 
Join Date: Aug 2002
Posts: 2,781
think in binary
blazin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2004, 08:24 AM   #3
jawanda
Confirmed User
 
Join Date: Feb 2003
Posts: 6,040
Alright, this might not be the cleanest approach, by try something like this.


A=2

While A is less than Input

A = A*2

Wend

Edit: Input = A/2
jawanda is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2004, 08:28 AM   #4
Ash@phpFX
Confirmed User
 
Join Date: Nov 2003
Posts: 4,292
Quote:
Originally posted by blazin
think in binary
Ash@phpFX is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2004, 09:38 AM   #5
Dusen
Confirmed User
 
Join Date: Aug 2002
Location: East Coast.
Posts: 2,251
Quote:
Originally posted by jawanda
Alright, this might not be the cleanest approach, by try something like this.


A=2

While A is less than Input

A = A*2

Wend

Edit: Input = A/2
This is currently what I'm doing, except after that I determine the distance between the value before and after the > value, then get the distance and choose it.

blazin: Thanks, I will :D
Dusen is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.