短十进制数的纠错
我有短的、可变长度的十进制数字,例如:#41551
,它们是由人类手动转录的。输入错误会导致不良结果,所以我的第一个想法是使用 Luhn 算法添加校验和 - #41551-3
。然而,这只会检测到错误,而不会纠正它。看来添加另一个校验位应该能够检测并纠正个位数错误,因此给定#41515-3?
(换位错误)我能够恢复正确的#41551
。
像汉明码这样的东西似乎是合适的地方,但我无法弄清楚如何将它们应用于十进制数据,而不是二进制数据。是否有专门用于此用途的算法,或者 Hamming/Reed-Solomon 等可以适应这种情况吗?
I have short, variable length decimal numbers, like: #41551
, that are manually transcribed by humans. Mistyping one will cause undesirable results, so my first thought is to use the Luhn algorithm to add a checksum -- #41551-3
. However, that will only detect an error, not correct it. It seems adding another check digit should be able to detect and correct a single-digit error, so given #41515-3?
(a transposition error) I'd be able to recover the correct #41551
.
Something like a Hamming code seems like the right place to look, but I haven't been able to figure out how to apply them to decimal, instead of binary, data. Is there an algorithm intended for this use, or can Hamming/Reed-Solomon etc be adapted to this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您还可以使用汉明码和检查方程进行校正。使用数据模 10 求和来查找校验位。将校验位放在 1、2、4、8、... 位置。
Yes, you can use Hamming codes in addition with check equations for correction. Use summation of data modulo 10 for finding check digits. Place check digits in 1,2,4,8, ... positions.
我只能提供带有五个额外数字的算法。
注意:5 个原始数字确实是最坏的情况。
通过 5 个额外数字,您可以对最多 11 个原始数字进行 ECC。
这类似于经典的 ECC 计算,但采用十进制:
原始(十进制)5 位数字:o0,o1,o2,o3,o4
按以下方式将数字分配到位置 0..9:
计算位置 1,2,4 处的数字, 8 像这样:
在此计算之后,计算位置处的数字:
然后您可以像这样重新洗牌:
要检查按以下顺序写入所有数字:
然后计算:
如果c0',c1',c2',c3',c4'全部为零则没有错误。
如果有一些非零的 c[0..3]' 且全部非零
c[0..3]' 的值为 c4',则一位数有错误。
您可以计算出错误数字的位置并进行更正。
(练习留给读者)。
如果 c[0..3]' 全部为零,并且只有 c4' 不等于零,则 c4 中存在一位数错误。
如果 ac[0..3]' 不等于 0 并且具有与 c4' 不同的值,那么您(至少)有两个数字的不可纠正的双重错误。
I can only provide an algorithm with FIVE extra digits.
Note: 5 original digits is really a worst case.
With FIVE extra digits you can do ECC for up to 11 original digits.
This like classical ECC calculations but in decimal:
Original (decimal) 5-digit number: o0,o1,o2,o3,o4
Distribute digits to positions 0..9 in the following manner:
Calculate digits at positions 1,2,4,8 like this:
AFTER this calculation, calculate digit at position:
You might then reshuffle like this:
To check write all digits in the following order:
Then calculate:
If c0',c1',c2',c3',c4' are all zero then there is no error.
If there are some c[0..3]' which are non-zero and ALL of the non-zero
c[0..3]' have the value c4', then there is an error in one digit.
You can calculate the position of the erroneous digit and correct.
(Exercise left to the reader).
If c[0..3]' are all zero and only c4' is unequal zero, then you have a one digit error in c4.
If a c[0..3]' is unequal zero and has a different value than c4' then you have (at least) an uncorrectable double error in two digits.
我尝试使用 Reed-Solomon,生成一个 3 位代码,最多可以纠正 1 位数字: https: //epxx.co/artigos/edc2_en.html
I tried to use Reed-Solomon, generating a 3-digit code that can correct up to 1 digit: https://epxx.co/artigos/edc2_en.html