Working in the maritime shipping industry, I find myself constantly entertained by the complexities of every facet of the field. Even what you think may be the most mundane part can be fascinating. Take a look at the container, 20′ long x 8′ wide x 8′ 6” high. It’s a cube that we all know from driving down the highway, on the railway, or on a boat at sea, but what are the numbers on the side. Where did they come from and what do they mean?
Each container has a unique identifier make up of 11alpha numeric digits. Four letters and seven numbers the last digit is known as the check digit to validate the first 10 digits. The reason that this exists is because often when receiving a vessel stow plan or rail consist, the container is sent through EDI with only 10 digits. Then when the vessel, train, or truck gets to the terminal it is brought into the gate, and handled by equipment that user OCR. OCR stands for optical character recognition, this is used to read the container number as the container gets handled. We then use the container number and check digit to match with the the consist or stow plan.
Owner code – Consists of three capital letters of the Latin alphabet to indicate the owner or principal operator of the container.
Category Identifier – Consists of one of the following capital letters of the Latin alphabet:
– U for all freight containers
– J for detachable freight container-related equipment
– Z for trailers and chassis
Serial number – 6 numeric digits, assigned by the owner or operator, uniquely identifying the container within that owner/operator’s fleet.
Check Digit – one numeric digit providing a means of validating the recording and transmission accuracy of the owner code and serial number.
ISO-6346 is an international standard covering the coding, identification and marking of intermodal containers. The standard establishes a visual identification system for every container that includes a unique serial number (with check digit), the owner, a country code, a size, type and equipment category as well as any operational marks. The register of container owners is managed by the International Container Bureau (BIC). The ISO-6346 has set the standard for how the unique identifier number (Check digit) is calculated.
Check Digit Calculation
Step 1 – An equivalent numerical value is assigned to each letter of the alphabet, beginning with 10 for the letter A (11 and multiples thereof are omitted)
A | B | C | D | E | F | G | H | I | J | K | L | M |
10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 |
N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | 35 | 36 | 37 | 38 |
Step 2 – Each of the numbers calculated in step 1 is multiplied by 2position, where position is the exponent to base 2. Position starts at 0, from left to right.
1. nbr | 2. nbr | 3. nbr | 4. nbr | 5. nbr | 6. nbr | 7. nbr | 8. nbr | 9. nbr | 10. nbr |
20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 256 | 512 |
Step 3 – Sum up all results of Step above
– 3a. Divide them by 11
– 3b. Round the result down towards zero i.e. make the result a whole number (integer)
– 3c. Multiply the integer value by 11
– 3d. Subtract result of (iv) from result of (i): This is the check digit.
If the final difference is 10, then the check digit becomes 0. To ensure that this does not happen the standard recommends that serial numbers should not be used which produce a final difference of 10; however, there are containers in the market which do not follow this recommendation, so handling this case has to be included if a check digit calculator is programmed
Example:
C | S | Q | U | 3 | 0 | 5 | 4 | 3 | 8 | Calc. | |
---|---|---|---|---|---|---|---|---|---|---|---|
13 | 30 | 28 | 32 | 3 | 0 | 5 | 4 | 3 | 8 | ||
× | 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 256 | 512 | |
13 | 60 | 112 | 256 | 48 | 0 | 320 | 512 | 768 | 4096 | 6185 [a] | |
b) Division by 11: | 562.272… | ||||||||||
c) Erase decimal digits: | 562 | ||||||||||
d) Multiply by 11: | 6182 | ||||||||||
a) minus d) = Check Digit: | 3 |
You can create your own check digit calculator web app using google apps scripts:
Link to the complete web app: https://script.google.com/macros/s/AKfycbxQ6D8GXsrTBrOxJto64xQG1JIoaoNXidP1ydL5Yq1qBveB0WxraJ7sa0RJoB-45FnR/exec
Link to GitHub Repository:
https://github.com/jcorky/Check-Digit-Calculator-Google-Scripts
code.gs
// Container layout check
// First four of the container id must be letters
let layout = /^([A-Z]{4})([0-9]{6,7})$/;
let match = container.match(layout);
//need to handle if the container is not in the correct layout.
if (!match) {
results.push(`Error: Container number "${container}" doesn't match the correct format: 4 alpha characters followed by 6-7 numerical characters.`);
continue;
}
let prefix = match[1];
let numPart = match[2];
// 4th letter check
// we are only calculating containers not chassis or container equipment (reefers, etc..)
if (prefix[3] === 'Z' || prefix[3] === 'J') {
results.push(`Error: Invalid fourth letter in container number "${container}". "Z" and "J" are not allowed.`);
continue;
}
// Calculate check digit
let contLessDigit = prefix + numPart.substring(0, 6); // Use first 6 digits of the numerical part
var sum = 0;
for (let i = 0; i < 10; i++) {
// Map letters to numbers
let n = contLessDigit.charCodeAt(i);
n -= n < 58 ? 48 : 55;
// Numbers 11, 22, 33 are omitted
n += (n - 1) / 10;
// Sum of all numbers multiplied by weighting
sum += n << i;
}
let checkDigit = sum % 11 % 10;
results.push(`${container.substring(0,10)}${checkDigit}`);
}
return results;
}
index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
*<style>
*body {
font-family: Arial, sans-serif;
color: #000;
margin: 0;
padding: 20px;
background-image: url('https://images.unsplash.com/photo-1583861682202-73deeff7cf97?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1974&q=80'); /* Replace with the URL of the corrugated containers image */
background-repeat: repeat;
background-size: auto;
}
h1 {
font-size: 24px;
margin-bottom: 20px;
}
input[type="text"] {
padding: 10px;
font-size: 16px;
width: 400px;
margin-bottom: 10px;
}
button {
padding: 10px 20px;
font-size: 16px;
background-color: #4caf50;
color: #fff;
border: none;
cursor: pointer;
}
ul {
list-style-type: none;
padding: 10px;
background-color: #fff;
border: 2px solid #000;
margin-top: 20px;
margin-bottom: 20px;
max-width: 600px;
margin-left: auto;
margin-right: auto;
}
li {
font-size: 16px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Enter Container Numbers</h1>
<input type="text" id="containerNumbers" placeholder="Enter numbers separated by commas...">
<button onclick="getCheckDigits()">Submit</button>
<ul id="result"></ul>
<script>
function getCheckDigits() {
var containerNumbers = document.getElementById('containerNumbers').value;
var containers = containerNumbers.replace(/\s/g, '').split(',');
google.script.run.withSuccessHandler(showResults).calculateCheckDigit(containers);
}
function showResults(results) {
var resultDiv = document.getElementById('result');
resultDiv.innerHTML = '';
for (var i = 0; i < results.length; i++) {
var li = document.createElement('li');
li.textContent = results[i];
resultDiv.appendChild(li);
}
}
</script>
</body>
</html>