[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[altq 1067] Re: Accuracy of atobps(const char*)
well, Kbps is kilo bits per second...the general convention is 1000 when
bits are involved, and 1024 (2^10) when bytes are involved...
------------------------------------------------------------------------
Sankaran Narayanan http://www.cs.columbia.edu/~sankaran
> -----Original Message-----
> From: owner-altq@csl.sony.co.jp [mailto:owner-altq@csl.sony.co.jp]On
> Behalf Of Nicolas Christin
> Sent: Wednesday, October 03, 2001 5:37 PM
> To: ALTQ Mailing List
> Subject: [altq 1066] Accuracy of atobps(const char*)
>
>
> Hi everyone,
>
> I have a really dumb question. In
> ALTQ/tbrconfig/tbrconfig.c, one can
> find the following procedure, which is in charge of converting a string
> describing a throughput/rate to an actual number (u_long):
>
> static u_long
> atobps(const char *s)
> {
> u_long bandwidth;
> char *cp;
>
> bandwidth = strtoul(s, &cp, 0);
> if (cp != NULL) {
> if (*cp == 'K' || *cp == 'k')
> bandwidth *= 1000;
> else if (*cp == 'M' || *cp == 'm')
> bandwidth *= 1000000;
> else if (*cp == 'G' || *cp == 'g')
> bandwidth *= 1000000000;
> }
> return (bandwidth);
> }
>
> My question is: Is this procedure correct? I thought 1 Kbps
> = 2^10 bps
> and *not* 1000 bps (same for Mbps, 2^20 != 10^6, and Gbps).
>
> It's just a minor detail anyways, but I thought I'd just
> ask. If I am
> correct, we should have a patch looking like:
>
> - bandwidth *= 1000;
> + bandwidth <<= 10;
> -------
> - bandwidth *= 1000000;
> + bandwidth <<= 20;
> -------
> - bandwidth *= 1000000000;
> + bandwidth <<= 30;
>
> Cheers,
> --Nick
>
> ------------------------------------------------------------------------
> Nicolas Christin nicolas@cs.virginia.edu
> Multimedia Networks Group http://www.cs.virginia.edu/~nc2y
> ------------------------------------------------------------------------