473,410 Members | 1,872 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,410 software developers and data experts.

How to print a 32-bit number as a base-10 number

Hi,

Assuming that "division" is a very costly operation (except by any
multiples of 2), whats the fastest way of printing a 32-bit number as a
base-10 unsigned integer.

Thanks
Steve

Nov 14 '05 #1
5 2171
On 13 Dec 2004 04:15:11 -0800
"Steve" <st************@yahoo.com> wrote:
Assuming that "division" is a very costly operation (except by any
multiples of 2), whats the fastest way of printing a 32-bit number as
a base-10 unsigned integer.


puts("a 32-bit number as a base-10 unsigned integer.");

The C language does not define the relative speed of different
operations. printf and friends on your implementation might be highly
optimised assembler that you could not beet using C, or it might be
incredibly slow and easy to beet in C. It might be fastest to use
multiply and shift down (I know one processor where this is definitely
true) or multiple might be slow and you are best using a shift and
add/subtract algorithm.

In short, if you want to know what is fast for your implementation you
need to ask in a group dedicated to your platform.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #2
Steve wrote:
Hi,

Assuming that "division" is a very costly operation (except by any
multiples of 2),
Why do you say that? Have you looked at the time complexity of integer
division/multiplication?
whats the fastest way of printing a 32-bit number as a
base-10 unsigned integer.

Thanks
Steve


printf("%d",number);

gtoomey
Nov 14 '05 #3

"Gregory Toomey" <no****@bigpond.com> wrote in message
news:32*************@individual.net...
Steve wrote:
Hi,

Assuming that "division" is a very costly operation (except by any
multiples of 2),


Why do you say that?


It was in his assignment.
Nov 14 '05 #4

"Steve" <st************@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Assuming that "division" is a very costly operation (except by any
multiples of 2), whats the fastest way of printing a 32-bit number as a
base-10 unsigned integer.


Printing a number goes through the I/O system, which is commonly orders of
magnitude slower than a few divides. You'll likely never notice the overhead
of the divides when printing numbers.

Assumptions about where a program is spending its time are usually wrong,
even when assumed by experts. A profiler will give you accurate information
that is often surprising.

Digital Mars C is a free download and comes with a profiler
www.digitalmars.com/ctg/trace.html.

-Walter
www.digitalmars.com free C, C++, D compilers
Nov 14 '05 #5
Steve wrote:
Hi,

Assuming that "division" is a very costly operation (except by any
multiples of 2), whats the fastest way of printing a 32-bit number as a
base-10 unsigned integer.


The fastest way (in terms of execution) is completely
implement-dependent. The fastest way to write it is with printf:

#include <stdio.h>

int main(void)
{
unsigned long x = 42; /* note that the guaranteed range of 'int'
is not sufficient. */
printf("%lu\n", x);
return 0;
}
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Henri Schomäcker | last post by:
Hi folks, I got a windows com executable which returns a jpg image in a BSTR. Let's say, the var that holds the data is $imgData. With perl, in a cgi script, I may simpy write:...
19
by: Karl Scalet | last post by:
Hi, quite often there is a need to just print out the items of a list. that would be nice, except prt() does not exist, and print is a statement not a function, hence cannot replace prt as...
30
by: Martin Bless | last post by:
Why can't we have an additional 'print' statement, that behaves exactly like 'print' but doesn't insert that damn blank between two arguments? Could be called 'printn' or 'prin1' or 'prinn'...
1
by: Franklin Marcano | last post by:
Greetings, Like to print series of registry in printer dot matrix (32 columns) that it has installed drivers generico single text, if they could pass algun Link or example to me of like doing it....
6
by: moondaddy | last post by:
I have an application where I need to print images where the size has been reduced down to a fraction of a thumbnail and the original image is several inches high and wide. We're using a special...
4
by: Gary | last post by:
Hello, I'm hoping someone can shed some light on why my report does not output the same results as shown in preview mode, which is to move the position of a check box based on a field value (see...
6
by: Kamilche | last post by:
I have a code snippet here that prints a dict in an arbitrary order. (Certain keys first, with rest appearing in sorted order). I didn't want to subclass dict, that's error-prone, and overkill for...
2
by: zlarson | last post by:
I have a website where a div's innerHTML is replaced with a string: <input type="button" name="myButton" id="myButton" onClick="printReport();"><IFRAME name="myFrame" id="myFrame"></IFRAME> which...
9
by: cniharral | last post by:
Hi, I'm interested in printing out coloured lines of my application and I don't know what to use. Can anybody give me an idea?? Regards. Carlos Niharra López
13
by: ramif | last post by:
Is there a way to print extended ASCII in C?? I tried to code something, but it only displays strange symbols. here is my code: main() { char chr = 177; //stores the extended ASCII...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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,...
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.