# How to Convert Bytes to KB in Python

How to Convert Bytes to KB in Python? In this article, we will discuss how to convert bytes into KBs in Python programming language. We will see how to convert KBs into bytes in Python. So, let’s start from the beginning. Firstly, we will discuss what Byte is and what is KB or KiloByte.

Byte:- A byte is a unit of data memory equal to eight bits, depending on whether 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.

KiloByte (KB):- The KILOBYTE is a unit of computer information or computer memory equivalent to 1024 bytes.

The formula for Converting KiloByte to Bytes:-
1 KiloByte = 1024 Byte

The formula for Converting Bytes to KiloByte:-
1 Byte = 1/1024 KiloByte

## Program to Convert Bytes to KB in Python

Here, we are writing a program to convert Bytes into KiloBytes in Python programming language. One KiloByte is equal to 1024 bytes therefore one byte is equivalent to 1/1024 KBs.

``````byte = int(input("Enter Bytes: "))
kb = byte/1024
print("{} KB".format(kb))``````

Output:-

Enter Bytes: 2048
2.0 KB

Enter Bytes: 5678
5.544921875 KB

Enter Bytes: 555555555
542534.7216796875 KB

## Program to Convert KB to Bytes in Python

Here, we have written a simple program for the conversion of KiloBytes into bytes in the Python programming language. Since 1 KiloByte is equivalent to 1024 bytes, therefore, to calculate KB (KiloBytes) to Bytes we have to multiply the given KiloBytes by 1024 and it will give the total number of the bytes.

``````kb = int(input("Enter KB: "))
byte = kb*(1024)
print("{} Bytes".format(byte))``````

Output:-

Enter KB: 2048
2097152 Bytes

Enter KB: 3
3072 Bytes

We have discussed how to convert bytes into KBs in Python programming language and we had also seen a program for how to convert KBs into bytes in Python. With the help of these programs, we can convert KB to Bytes and vice-versa.

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!