Jump to content

Creating check digit from Hex code number


Cep

Recommended Posts

Hello,

 

I am trying to create a unique reference number with the following convention,

 

first char = region code

4 hex digits = decimal id number

final char = check digit

 

I have come up with a little function that I want to test out but I am having a problem type juggling the string into a hex number in order to perform the calculation.

 

Can anyone help me because I do not understand what is wrong?

 

<?php

$a = "FA45C6";

function breakdown($code) {

$region = substr($code, 0);

$check = substr($code, -1, 1);

$hex = "0x".substr($code, 1, -1);

$calc = (int)$hex % 10;

if ($calc==$check) {
	echo "We have a correct check digit";
} else {
	echo "Houston we have a problem - calc is {$calc}";
}

}

breakdown($a);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.