473,412 Members | 2,027 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,412 software developers and data experts.

How do I determine the number of round numbers (to be explained below)?

NOTE: I am using Excel VBA.

Please help me program the following problem:

A positive integer n is said to be a ROUND NUMBER if the binary representation of n has as many or more zeros as ones. For example:

The integer 9, written in binary form, is 1001. 1001 has two zeros and two ones; thus 9 is a ROUND NUMBER.

The integer 26, written in binary form, is 11010. 11010 has two zeros and three ones; thus 26 is not a ROUND NUMBER.

Write a program which will accept a positive integer k as input and print out the numbers of ROUND NUMBERS less than or equal to k in the following format:

THERE ARE XXX ROUND NUMBERS LESS THAN OR EQUAL TO K

Sample Run
Input: K= 10
Output: THERE ARE 5 ROUND NUMBERS LESS THAN OR EQUAL TO 10.

Input: K= 100
Output: THERE ARE 47 ROUND NUMBERS LESS THAN OR EQUAL TO 100.

I have already managed to convert decimal to binary and to get the number of zeroes and number of ones. I just can't figure out how to do the following: 1) Do the entire thing for the whole range. Example, how do I get the binary equivalent of 5, 4, 3, 2, and 1 simultaneously? I can only get the binary equivalent of one decimal at a time. I've been doing this since last night... The deadline for this is later at 11:59 PM. Please do help me... Thank you very much!

P.S. Please leave me a private message if you want to see the codes that I have managed to do so far. I read in your site that I should not post the codes that I have done so as to prevent plagiarism. Thank you!
May 9 '10 #1
4 1506
Please guys I really really need your help... Whenever I use For & Next, things get messed up. So I don't know what else to use in order to loop the whole thing... Please help me! :(
May 9 '10 #2
vb5prgrmr
305 Expert 100+
Search for vb6 decimal binary with your friends (yahoo, google, ask, answers, bing) as I know there is code out there to do this conversion...



Good Luck
May 9 '10 #3
@vb5prgrmr
Thank you for the reply! I have been doing so for like hours already and the codes are really complicated compared to what I have done... >_<
May 9 '10 #4
Guido Geurs
767 Expert 512MB
dear,

Just do a For...next from 1 to K , check If round number and enter in a counter with "counter=counter+1" each time you have a round number.

send a msgbox with ("THERE ARE " & counter & " ROUND NUMBERS LESS THAN OR EQUAL TO " & k)
br,
May 10 '10 #5

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

Similar topics

4
by: Bart Plessers \(artabel\) | last post by:
Hello, I have an asp script that lists the files in a directory: CurrentPATH = "c:\temp\" Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFolder = oFSO.GetFolder(CurrentPATH) Set...
8
by: Steven | last post by:
Hi, I am trying to find out how many digits there are in a given number. The macro listed below works fine when applied to an INT, however when doing Doubles with numbers > then a billion ?? It...
9
by: Lance Hoffmeyer | last post by:
Is there an easy way to round numbers in an array? I have Test = and want to round so the values are print Test
10
by: Henrootje | last post by:
I am looking for a way to round down the results of a calculation in a query f.e.: in a query this calculation is performed: a/b = c 5/3 = 1,666666667
3
by: Samuel | last post by:
Hi I am looking for a method that rounds numbers to a specified number of decimal places for example if I pass 2.455 it will return 2.46 Thank you, Samuel
10
by: slider | last post by:
hey all, i have a set of numbers which looks like this 21551878283310414135344613310414135344613310468612568833104686125688331043180057716331044879441661331045148067733104487944166133104 ...
3
by: Aussie Rules | last post by:
Hi, Whats the easiest way to round numbers up. For example, a calculation that results in a value of 1.3 will round to 1, and a calculation that results in 1.8 will round to 2. My issue...
3
by: =?Utf-8?B?RWR3aW4=?= | last post by:
What I am trying to do is come up with a way to determine how many unique extensions there are within a directory and its sub directories. Within the loop that recurses root folder, I am...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.