I have a staff numbers arranged sequentially
like
1
100
101
102
103
.
.
.
2
200
201
.
.
and i make a binary search on them
but i faced a problem that
in sequential numbers consider 2>103
but when comparing between these two number in binary serach consider 103>2
because the number of digits in 103 bigger than the number of digits in 2
is there a way to compare between sequential number without facing this problem
please help

Solution 4

If you have to sort these as a string, and you know the maximum length of the string, then zero-pad them. i.e. if the maximum length is 10 digits, then change "1" to "0000000001". Then the ordering will work.
Howeever, if you know they are always going to consist only of digits, you probably want to store them as integers, as PIEBALDconsult suggested.
Regards,
Ian.