PHP script to convert B/s to Mbps

Posted on 2014-08-07
Last Modified: 2014-08-07
I need help creating a function that accepts Bytes per sec and converts that to Mbps.
Question by:ITNC
    LVL 107

    Expert Comment

    by:Ray Paseur
    Mbps - do you mean megabytes or megabits?
    LVL 107

    Accepted Solution

    With the commonly accepted terminology this should be OK.

    <?php // demo/temp_itnc.php
    // SEE
    // REF
    // 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


    Author Comment

    Megabits, thank you
    LVL 107

    Expert Comment

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

    Author Comment

    That worked perfect, thank you sir.
    LVL 107

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now