0

I have an application which crops a picture and returns the result to the ViewModel as a base64 string. I need to check whether the size is within 1 MB or exceeds it.

This is my solution:

byte[] byteArray = Convert.FromBase64String(input);

if (byteArray.Length > Constants.PictureMaximumSize)
{      
    return false;
}    

return true;

Where: Constants.PictureMaximumSize = 1048576;

My Question:

I want to check if it is up to 1 MB - should I compare the byte [] length to 1048576 or maybe to 1000000?

6
  • 6
    So your question is just “how many bytes are in a megabyte?” Couldn’t you google that? Commented Feb 27, 2018 at 17:30
  • 1
    I did and got both results. So I am asking here for clarification. Commented Feb 27, 2018 at 17:31
  • Did you look up the reason why you got both results? Commented Feb 27, 2018 at 17:36
  • Yes, I read that 1048576 is in binary and the other in decimal metric system. And here we come to the example about the byteArray.Length - I am not sure which one to compare it to. Commented Feb 27, 2018 at 17:39
  • My opinion would be for 1048576 , but I would like to have some sure opinions on this. Commented Feb 27, 2018 at 17:41

1 Answer 1

1

In common computing usage 1,048,576 bytes is considered a megabyte. However, the standards bodies IEEE, EU, ISO and NIST only consider 1,000,000 bytes as a megabyte.

So, you get to choose which you want. Do you want to follow the international standards? Or do you want to remain consistent with almost every piece of software in existence? We can't choose for you, that's up to you. We can't tell you which one to use, you need to examine the information and make the correct choice for your application and its users.

Keep in mind that if you refer to mebibyte, then you will be consistent with the international standards, and there is no ambiguity as to how many bytes are in a mebibyte, although that term is less well known and could be confusing to your users.

Wikipedia has backstory on why both numbers are considered as a megabyte in various situations.

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

1 Comment

Thank you very much. 1,048,576 bytes would be my choice.

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.