non-floating point 12-digit datatype?
is there a reason that you can't just store them as strings? I don't know much about barcodes but I don't think that you are going to be using any of the standard mathematical operators with them.
It would be waste of space, bit silly to store a number as string on computer, and slower to compare.
BTW one way how could you store it under C++ is: char barcode[12];
BTW one way how could you store it under C++ is: char barcode[12];
Quote:Original post by Raghar
It would be waste of space, bit silly to store a number as string on computer, and slower to compare.
BTW one way how could you store it under C++ is: char barcode[12];
We've secretly replaced Raghar's original second paragraph with one that completely contradicts his first. Let's see if he notices!
CM
It is worth noting that UPCs are inherantly a binary-coded decimal system. In other words, strings are a very natural way of representing them. Furthermore, individual decimal digits are needed at different stages depending on the specific item and use. So storing a UPC as a 64-bit binary number will yield numerous unneccessary binary to decimal conversions.
Just food for thought before dismissing strings as inefficient.
CM
Just food for thought before dismissing strings as inefficient.
CM
Something happened to the standard part of C++ library called string?
Actually I don't consider char array and a string as a synonym.
No definition of char array here either. ~_^
http://www.synonym.com/definition/string
Actually I don't consider char array and a string as a synonym.
No definition of char array here either. ~_^
http://www.synonym.com/definition/string
Another potential advantage of storing as a string/char array over long long is that maybe you don't want leading zeros on some codes and maybe you do on others - with a long long there'd be no easy way to differentiate them?
Another consideration is that by using a long long, you won't be able to deal with alphanumeric barcodes if that ever becomes an issue. SKUs are usually just numeric, but then you might get the bright idea to track UPS shipping labels. Which just happened to me a while ago.
Quote:It would be waste of space, bit silly to store a number as string on computer, and slower to compare.
But a bar code isn't really a number, it is an array of single digits. Exactly the kind of thing to store as a string. I doubt it would be much slower. Plus storing it as a string will make your code easier to write and maintain.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement