How to create a python byte converter

how to make python program such that when you type “MB” (for megabytes) and then the amount of megabytes you want and it would print it in bytes


Well first things first you need to understand the base two system that dictates the sizes.

1 bit is 2 or ON / OFF — 1 / 0
1 Nibble is 4 bits
1 byte is 2 nibbles or 8 bits
1 kilobyte is 1024 bytes
1 megabyte is 1024 kilobytes or 1048576 bits

Now all this is simple to express in math

1 bit is 21 bit
1 nibble is 22 bit
1 byte is 23 bit
1 kilobyte is 210 bit
1 megabyte is 220 bit

From this information it is quite easy to create a formula to tell you in what range each size is and then create a function that gives back the size from if/else.

If you need any more help feel free to ask.

never mind I already figured it out