Python Convert Bytes to MegaBytes

Python Convert Bytes to MegaBytes | In the previous program we had discussed how to convert bytes into KBs and how to convert KBs into bytes in Python. In this article, we will discuss how to convert bytes into MegaBytes in Python. Along with this we will also develop a program to convert MegaBytes into bytes. So, let’s start from the beginning. Firstly, we will discuss what is Byte and what is ṀBs or MegaBytes.

Byte:- A byte is a unit of data memory equal to eight bits, relying on whether or not it requires error correction. One byte is equivalent to eight bits. A byte is a unit most computers use to describe a character such as a number, letter, or typographic symbol. 

MegaByte:- A MegaByte is a unit of computer information or computer memory equivalent to one million or, strictly, 1,048,576 bytes.

The formula for Converting Bytes to Megabytes:-
1 Byte = 1/1048576 MegaBytes = 0.000000954 MegaBytes 

The formula for Converting Megabytes to Bytes:-
1 MegaByte = 1048576 Bytes 

Python Convert Bytes to MegaBytes

Now let us develop a simple program for the conversion of Bytes into MegaBytes in the Python programming language. Since 1 MegaByte is equivalent to 1048576 Bytes therefore 1 Byte is equal to 1/1048576 MegaBytes. Using this formula we can convert Bytes into MegaBytes.

byte = int(input("Enter Bytes: "))
mb = byte/1048576
print("{} MB".format(mb))


Enter Bytes: 1
9.5367431640625e-07 MB

Enter Bytes: 1048576
1.0 MB

Enter Bytes: 9437184
9.0 MB

Enter Bytes: 1024
0.0009765625 MB

Program to Convert MegaBytes to Bytes in Python

Here, we have written a simple program for the conversion of MegaBytes into Bytes in the Python programming language.

mb = int(input("Enter MegaBytes: "))
byte = mb*(1048576)
print("{} Bytes".format(byte))


Enter MegaBytes: 1
1048576 Bytes

Enter MegaBytes: 9
9437184 Bytes

Enter MegaBytes: 1024
1073741824 Bytes

So, here we have learned how to convert MegaBytes to Bytes and Bytes to MegaBytes using Python Programming Language. Hope you all find this article useful.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *