Posted By

abwaters on 03/19/09


Tagged

ISBN barcode


Versions (?)

Convert UPC to ISBN


 / Published in: Java
 

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

  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. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: abwaters on March 19, 2009

Converts an EAN style barcode to an ISBN

You need to login to post a comment.