Alex Rivera | Logout

integer and string comparison at system level

Asked 2011-07-19T01:58:41.143
9

How are integers and strings compared at a low level? Like whenever we use

int a = 11;
int b = 12;

compare(a,b); //Just an example comparison, not in any particular language.

And

String a = "11";
String b = "12";

compare(a,b);

Now what I am asking is what is the system level difference between these two comparisons?Question is not for any particular language, it's just a generic issue. It is also not regarding the string to integer conversion/comparison or vice-versa. I know that the answers might be different for different platforms and different languages, but as I have no clue about this I am just asking a generic question.

And why are integer comparisons always considered faster then string comparisons?

Edit
Report

1 Answer

2

the integers are stored as integer values represented in binary as a single set of 1's and zeroes, taking up a couple bytes (depending on the OS)

the strings are stored as one character per digit, each one using a bit pattern in its byte.

so in your example, the strings are taking up approximately twice the amount of bytes to represent as compared to the ints.

answered 2011-07-19T02:05:20.703

Your Answer