how to order a set of number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sakurasyi
    New Member
    • May 2006
    • 31

    how to order a set of number

    hai...

    i'm doing a simple program where it will sort a set of number from 1 to 100. for 1 to 9 it sort correctly. but after number 9 (10,11,...), the sort become 1,10,11, 12...,2,20,21,. .and so on. Can somebody tell me how to sort it correctly?

    thank you..
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    looks like you are doing a text sort rather than a binary sort. In a text sort each character of the number is considered in turn so for the numbers 10 and 2 the first characters are 1 and 2 and 1 < 2 therefore 10 < 2. A binary sort will compare the actual value of the number that is compare 10 with 2 therefore 2 < 10.

    You have not mentioned what system you are using but you need to make sure that you are doing a binary comparison, possibly by converting the text to binary data first.

    Comment

    • sakurasyi
      New Member
      • May 2006
      • 31

      #3
      thank you..

      dear banfa,

      you are correct..
      after convert the text to binary, it is work...
      thank you very much

      Comment

      Working...