Convert UPC to ISBN


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. if (isbn.length() == 13 && isbn.indexOf("978") == 0)
  2. {
  3. isbn = isbn.substring(3,12);
  4. int xsum = 0;
  5.  
  6. for (int i = 0; i < 9; i++)
  7. {
  8. xsum += (10 - i) * Character.getNumericValue(isbn.charAt(i));
  9. }
  10.  
  11. xsum %= 11;
  12. xsum = 11 - xsum;
  13.  
  14. String x_val = String.valueOf(xsum);
  15.  
  16. switch (xsum)
  17. {
  18. case 10: x_val = "X"; break;
  19. case 11: x_val = "0"; break;
  20. }
  21.  
  22. isbn += x_val;
  23. }

URL: http://www.eblong.com/zarf/bookscan/eantoisbn-java.txt

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.