0

I have a field on my web application that requires a KB. This is then reflected in the URL of the web app in Bytes form.

Can I convert a string of "500" KB to a string of Bytes in Python (expecting to get around "500000")?

1 Answer 1

1

From Wikipedia:

The kilobyte is a multiple of the unit byte for digital information. The International System of Units (SI) defines the prefix kilo as 1000 (103); therefore one kilobyte is 1000 bytes.

You can simply cast it to an integer,multiply it by 1000, and return it to a string like this:

>>> size_in_kb = "500"
>>> bytes = str(int(size_in_kb) * 1000)
>>> bytes
'500000'

Note: you can multiply it with 1024 instead of 1000, depends on your exact needs

Sign up to request clarification or add additional context in comments.

1 Comment

i think It would be better using 1024

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.