UPC: Difference between revisions
Content added Content deleted
m (added highlighting and whitespace, corrected some misspellings.) |
m (added ;Goal:, ;Task;, ;Sample input:, ;Verification; section headers, split the UPC-A bar code structure into separate bullet points, added whitespace.) |
||
Line 1: | Line 1: | ||
{{draft task}} |
{{draft task}} |
||
⚫ | |||
;Goal: |
|||
Convert UPC bar codes to decimal. |
Convert UPC bar codes to decimal. |
||
Line 8: | Line 9: | ||
The [[wp:Universal_Product_Code|UPC]] standard is actually a collection of standards -- physical standards, data format standards, product reference standards... |
The [[wp:Universal_Product_Code|UPC]] standard is actually a collection of standards -- physical standards, data format standards, product reference standards... |
||
Here, we focus on some of the data format standards, with an imaginary physical+electrical implementation which converts physical UPC bar codes to ASCII with spaces and '''#''' characters representing the presence or absence of ink. |
Here, in this task, we will focus on some of the data format standards, with an imaginary physical+electrical implementation which converts physical UPC bar codes to ASCII (with spaces and '''#''' characters representing the presence or absence of ink). |
||
⚫ | |||
;Sample input: |
|||
⚫ | |||
<pre> |
<pre> |
||
# # # ## # ## # ## ### ## ### ## #### # # # ## ## # # ## ## ### # ## ## ### # # # |
# # # ## # ## # ## ### ## ### ## #### # # # ## ## # # ## ## ### # ## ## ### # # # |
||
Line 24: | Line 26: | ||
# # # #### ## # #### # # ## ## ### #### # # # # ### # ### ### # # ### # # # ### # # |
# # # #### ## # #### # # ## ## ### #### # # # # ### # ### ### # # ### # # # ### # # |
||
</pre> |
</pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
Implement code to find the corresponding decimal representation of each, rejecting the error. |
|||
Extra credit for handling the rows entered upside down (the other option is to reject them). |
Extra credit for handling the rows entered upside down (the other option is to reject them). |
||
Notes: |
;Notes: |
||
Each digit is represented by 7 bits: |
Each digit is represented by 7 bits: |
||
<pre> |
<pre> |
||
0: 0 0 0 1 1 0 1 |
0: 0 0 0 1 1 0 1 |
||
1: 0 0 1 1 0 0 1 |
1: 0 0 1 1 0 0 1 |
||
2: 0 0 1 0 0 1 1 |
2: 0 0 1 0 0 1 1 |
||
3: 0 1 1 1 1 0 1 |
3: 0 1 1 1 1 0 1 |
||
4: 0 1 0 0 0 1 1 |
4: 0 1 0 0 0 1 1 |
||
5: 0 1 1 0 0 0 1 |
5: 0 1 1 0 0 0 1 |
||
6: 0 1 0 1 1 1 1 |
6: 0 1 0 1 1 1 1 |
||
7: 0 1 1 1 0 1 1 |
7: 0 1 1 1 0 1 1 |
||
8: 0 1 1 0 1 1 1 |
8: 0 1 1 0 1 1 1 |
||
9: 0 0 0 1 0 1 1 |
9: 0 0 0 1 0 1 1 |
||
</pre> |
</pre> |
||
On the left hand side of the bar code a space represents a '''0''' and a '''#''' represents a '''1'''. |
|||
<br>On the right hand side of the bar code, a '''#''' represents a '''0''' and a space represents a '''1''' |
|||
⚫ | |||
⚫ | |||
The UPC-A bar code structure begins with at least 9 spaces (which our imaginary bar code reader unfortunately doesn't always reproduce properly), then has a '''# #''' sequence marking the start of the sequence, then has the six "left hand" digits, then has a ''' # # ''' sequence in the middle, then has the six "right hand digits" and finally ends with another '''# #''' end sequence and nine trailing spaces (which might be eaten by wiki edits and in any event were not quite captured correctly by our imaginary bar code reader). |
|||
;The UPC-A bar code structure: |
|||
::* It begins with at least 9 spaces (which our imaginary bar code reader unfortunately doesn't always reproduce properly), |
|||
::* then has a ''' # # ''' sequence marking the start of the sequence, |
|||
::* then has the six "left hand" digits, |
|||
::* then has a ''' # # ''' sequence in the middle, |
|||
::* then has the six "right hand digits", |
|||
::* then has another ''' # # ''' (end sequence), and finally, |
|||
::* then ends with nine trailing spaces (which might be eaten by wiki edits and in any event were not quite captured correctly by our imaginary bar code reader). |
|||
Finally, the last digit is a checksum digit which may be used to help detect errors. |
Finally, the last digit is a checksum digit which may be used to help detect errors. |
||
⚫ | |||
;Verification: |
|||
⚫ | |||
The sum (mod 10) must be '''0''' (must have a zero as its last digit) if the UPC number has been read correctly. |
|||
<br><br> |
<br><br> |
||