十六进制数如何实现循环递增?

caoping8512 2011-12-30 01:25:53
给定了一个MAC地址区间为 B8A386462CC0—B8A38647171F, 十六进制。如何用C#实现该MAC地址每循环一次,自增3,然后显示出所有这个区间内生产的MAC地址列表。
谢谢!
...全文
1391 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
烟波钓 2011-12-30
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 caoping8512 的回复:]
引用 2 楼 qldsrx 的回复:
用BigInteger类来处理,项目需要添加System.Numerics的引用

C# code
BigInteger a = BigInteger.Parse("B8A386462CC0", System.Globalization.NumberStyles.HexNumber);
a += 3;
Console……

2楼,谢谢你的回答。……
[/Quote]
添加引用 在你的项目中
caoping8512 2011-12-30
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 qldsrx 的回复:]
用BigInteger类来处理,项目需要添加System.Numerics的引用

C# code
BigInteger a = BigInteger.Parse("B8A386462CC0", System.Globalization.NumberStyles.HexNumber);
a += 3;
Console……
[/Quote]
2楼,谢谢你的回答。
可是为什么我加了using System.Numerics后,却报错“错误 2 命名空间“System”中不存在类型或命名空间名称“Numerics”(是缺少程序集引用吗?) ”??
浮生若梦丶 2011-12-30
  • 打赏
  • 举报
回复
特别 2011-12-30
  • 打赏
  • 举报
回复
用long类型来循环一样的,

for (long i = 0xB8A386462CC0; i <= 0xB8A38647171F; i=i+3 )
{

}

其实B8A386462CC0—B8A38647171F之间也不过就是59999,也可以这样

int a = (int)(0xB8A38647171F - 0xB8A386462CC0);
for (int i = 0; i < a; i++,i++,i++)
{
long num = 0xB8A38647171F + i;
}
qldsrx 2011-12-30
  • 打赏
  • 举报
回复
用BigInteger类来处理,项目需要添加System.Numerics的引用
            BigInteger a = BigInteger.Parse("B8A386462CC0", System.Globalization.NumberStyles.HexNumber);
a += 3;
Console.WriteLine(a.ToString("X2"));
阿云ivan 2011-12-30
  • 打赏
  • 举报
回复
转换为10进制处理,处理完后再转换为16进制
二进制十六进制的相互转换 c6下完美运行通过 #include #include #include #include void convert(char *input, char *output) { int len1 = strlen(input); //输入二进制 int pos = len1 / 4 + 1; //输出十六进制的位 if (len1 % 4 == 0) { pos = pos - 1; } int j = 0; while (len1>0) { char sum = 0; for (int i=0; i0; i++, len1--) //从最后起每4位算一次值 { sum = sum + (input[len1-1]-'0')*pow(2, i); } // 转换成16进制表示 sum = sum + '0'; if ('9'数!\n"); exit(0); } //十六进制放到output组相应位置 output[--pos] = sum; } } int main() { int groupNum = 0; char total[1024] = {0}; scanf("%d", &groupNum); for (int i=1; i<=groupNum; i++) { char input[1024] = {0}; char output[256] = {0}; fflush(stdin); //记得清楚输入缓冲区,否则每次回车会影响 gets(input); convert(input, output); char format[32] = {0}; sprintf(format, "\nCase %d: ", i); strcat(total, format); strcat(total, output); } printf("%s\n", total); } 不分手de恋爱 10:52:05 /二进制十六进制的相互转换 c6下完美运行通过 #include #include #include #include void convert(char *input, char *output) { int len1 = strlen(input); //输入二进制 int pos = len1 / 4 + 1; //输出十六进制的位 if (len1 % 4 == 0) { pos = pos - 1; } int j = 0; while (len1>0) { char sum = 0; for (int i=0; i0; i++, len1--) //从最后起每4位算一次值 { sum = sum + (input[len1-1]-'0')*pow(2, i); } // 转换成16进制表示 sum = sum + '0'; if ('9'数!\n"); exit(0); } //十六进制放到output组相应位置 output[--pos] = sum; } } int main() { int groupNum = 0; char total[1024] = {0}; scanf("%d", &groupNum); for (int i=1; i<=groupNum; i++) { char input[1024] = {0}; char output[256] = {0}; fflush(stdin); //记得清楚输入缓冲区,否则每次回车会影响 gets(input); convert(input, output); char format[32] = {0}; sprintf(format, "\nCase %d: ", i); strcat(total, format); strcat(total, output); } printf("%s\n", total); }

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧