惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
腾讯CDC
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
博客园_首页
D
DataBreaches.Net
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
月光博客
月光博客
Jina AI
Jina AI
Stack Overflow Blog
Stack Overflow Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
Vercel News
Vercel News
WordPress大学
WordPress大学
J
Java Code Geeks
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42

博客园 - 梅子黄时雨

离职反思 人际交往能力:远比你想象的重要 关于晋升 生产力提升计划 向企业一样的思考 在CentOS上搭建WordPress的博客系统 Some Useful LINQ Extension Methods MVC模式 IIS7.5配置 An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode. 显式接口成员实现 C#实现的堆栈 ASP.NET 验证控件 Gridview中合并单元格,某字段的内容相同时如何只显示一个,屏蔽相同列或行的内容(转) C#winform 配置webconfig 动态SQL EXEC DELL 1520 笔记本拆机 关于表变量 华为致新员工书
C# 整数和byte数组互换
梅子黄时雨 · 2012-03-06 · via 博客园 - 梅子黄时雨
   1:          public static byte[] int2Byte(int intValue)
   2:          {
   3:              byte[] b = new byte[4];
   4:              for (int i = 0; i < 4; i++)
   5:              {
   6:                  b[i] = (byte)(intValue >> 8 * (i) & 0xFF);
   7:              }
   8:              return b;
   9:          }
  10:   
  11:          // 将iSource转为长度为iArrayLen的byte数组,字节数组的低位是整型的低字节位
  12:          public static byte[] int2Byte(int iSource, int len)
  13:          {
  14:              byte[] b = new byte[len];
  15:              for (int i = 0; (i < 4) && (i < len); i++)
  16:              {
  17:                  b[i] = (byte)(iSource >> 8 * i & 0xFF);
  18:              }
  19:              return b;
  20:          }
  21:   
  22:          // 将byte数组bRefArr转为一个整数,字节数组的低位是整型的低字节位
  23:          public static int byte2Int(byte[] b)
  24:          {
  25:              int iOutcome = 0;
  26:              byte bLoop;
  27:              for (int i = 0; i < 4; i++)
  28:              {
  29:                  bLoop = b[i];
  30:                  iOutcome += (bLoop & 0xFF) << (8 * i);
  31:              }
  32:              return iOutcome;
  33:          }