用Java编码代码
在过去的几周里,我读完了这本书错误控制编码:基础知识和应用程序 为了了解电信公司初级编程角色的 BCH(Bose、Chaudhuri、Hocquenghem)代码。
这本书主要涵盖了该主题背后的数学和理论,但我正在努力实现一些概念;主要是获取下一个 n 代码字。我有一个 GUI(通过 NetBeans 实现,因此我不会发布代码,因为文件很大),它传递代码以获取下一个 n 个数字:
生成这些数字是我遇到问题的地方。如果我可以仅在编码方法中完成所有这些,而不是使用 GUI 循环,我的生活将会轻松十倍。
这已经让我发疯了好几天了,因为从输入生成 0000000000 很容易,但我不知道从那里用我的代码去哪里。然后我该怎么做才能生成下一个工作号码?
任何有关生成上述代码的帮助将不胜感激。
Over the past couple of weeks I've read through the book Error Control Coding: Fundamentals and Applications in order to learn about BCH (Bose, Chaudhuri, Hocquenghem) Codes for an junior programming role at a telecoms company.
This book mostly covers the mathematics and theory behind the subject, but I'm struggling to implement some of the concepts; primarily getting the next n codewords.I have a GUI (implemented through NetBeans, so I won't post the code as the file is huge) that passes a code in order to get the next n numbers:
Generating these numbers is where I am having problems. If I could go through all of these within just the encoding method instead of looping through using the GUI my life would be ten times easier.
This has been driving me crazy for days now as it is easy enough to generate 0000000000 from the input, but I am lost as to where to go from there with my code. What do I then do to generate the next working number?
Any help with generating the above code would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(大编辑......)多玩一点代码,这似乎有效:
我更喜欢抛出异常而不是返回特殊字符串。在这种情况下,我忽略了异常,通常我会说这是不好的做法,但对于这种情况,我认为这就是你想要的。
(big edit...) Playing with the code a bit more this seems to work:
I prefer throwing the exception rather than returning a special string. In this case I ignore the exception which normally I would say is bad practice, but for this case I think it is what you want.
很难说,如果我遇到你的问题,但在多次阅读你的问题后,也许这就是你正在寻找的:
解决方案中有一个缺陷,toOctalString 结果不是 0 填充的。如果这就是您想要的,我建议在编码调用中使用
String.format("", i)
。更新
要在当前调用中使用它,请将对encoding(String str) 的调用替换为对此方法的调用。您将收到包含所有编码的有序列表。
我假设,您只对八进制值感兴趣 - 我的错误,现在我认为您只是忘记了示例中值 000009 的编码,从而删除了不相关的八进制内容。
Hard to tell, if I got your problem, but after reading your question several times, maybe that's what you're looking for:
There's one flaw in the solution, the toOctalString results are not 0-padded. If that's what you want, I suggest using
String.format("<something>", i)
in the encoding call.Update
To use it in your current call, replace a call to encoding(String str) with call to this method. You'll receive an ordered List with all encodings.
I aasumed, you were only interested in octal values - my mistake, now I think you just forgot the encoding for value 000009 in you example and thus removed the irretating octal stuff.