c# 填充前导八位字节
我的指数是 3 个字节长。现在我需要它是 4 个字节。我找到了可以填充前导八位字节的地方..但我不知道该怎么做..所以有人可以帮助我吗?
示例输入:我现在拥有的指数是 65537,然后是 int 字节 01 00 01。
i have exponent whats 3 bytes long. Now i need it to be 4 bytes. I found somewhere that i could pad at the leading octets.. but i have no idea to do that.. So can anybody help me out?
Example Input: exponent what i have right now is 65537, int bytes its then 01 00 01.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您只想用零填充它,创建一个新的四字节数组并将现有的复制到其中:(
您也可以通过三个赋值手动执行此操作;对于这种情况,这可能更简单,但扩展性不好(
如果您发现需要在末尾而不是开头进行填充,请将“1”更改为“0”...或在其中使用
Array.Resize 案件。
Assuming you just want to pad it with zeroes, create a new four byte array and copy the existing one into it:
(You can do this manually with three assignments as well; that's potentially simpler for this situation, but doesn't scale well (in terms of code) to larger sizes.)
Change the "1" to "0" if you find you need the padding at the end instead of the start... or use
Array.Resize
in that case.不完全确定其含义,但听起来您只是想要:
当然,如果您实际上正在处理
int
,那么它已经左侧填充 0,至 4 个字节。Not entirely sure of the meaning, but it sounds like you just want:
Of course, if you are actually dealing with an
int
it is already padded on the left with 0, to 4 bytes.