?
Solved

PHP script to convert B/s to Mbps

Posted on 2014-08-07
6
Medium Priority
?
212 Views
Last Modified: 2014-08-07
I need help creating a function that accepts Bytes per sec and converts that to Mbps.
0
Comment
Question by:ITNC
  • 4
  • 2
6 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40246868
Mbps - do you mean megabytes or megabits?
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 40246892
With the commonly accepted terminology this should be OK.

<?php // demo/temp_itnc.php
error_reporting(E_ALL);

// SEE http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28492897.html
// REF http://en.wikipedia.org/wiki/Data_rate_units

// EXAMPLE
$bytes = 50000000;
echo bs_to_mbps($bytes);

function bs_to_mbps($bytes, $precision=2)
{
    $mbps = $bytes / 125000;
    return number_format($mbps,$precision);
}

Open in new window

0
 

Author Comment

by:ITNC
ID: 40246930
Megabits, thank you
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40247031
This should cover it correctly.  Please let me know if you have any questions.
0
 

Author Comment

by:ITNC
ID: 40247036
That worked perfect, thank you sir.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40247043
Glad to help!  Thanks for the points and thanks for using E-E, ~Ray
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question