c# - 字节转换为 INT64,在引擎盖下
问题描述
再会。对于当前项目,我需要知道数据类型如何表示为字节。例如,如果我使用:
long three = 500;var bytes = BitConverter.GetBytes(three);
我得到值 244,1,0,0,0,0,0,0。我知道它是一个 64 位的值,并且 8 位进入一点,因此有 8 个字节。但是244和1是怎么组成500的呢?我试过用谷歌搜索它,但我得到的只是使用 BitConverter。我需要知道位转换器是如何工作的。如果有人可以向我指出一篇文章或解释这些东西是如何工作的,将不胜感激。
解决方案
这很简单。
BitConverter.GetBytes((long)1); // {1,0,0,0,0,0,0,0};
BitConverter.GetBytes((long)10); // {10,0,0,0,0,0,0,0};
BitConverter.GetBytes((long)100); // {100,0,0,0,0,0,0,0};
BitConverter.GetBytes((long)255); // {255,0,0,0,0,0,0,0};
BitConverter.GetBytes((long)256); // {0,1,0,0,0,0,0,0}; this 1 is 256
BitConverter.GetBytes((long)500); // {244,1,0,0,0,0,0,0}; this is yours 500 = 244 + 1 * 256
如果您需要源代码,您应该查看 Microsoft GitHub,因为实现是开源的 :) https://github.com/dotnet
推荐阅读
- getstream-io - 在 getstream 中代表分组的用户
- php - 如何在 Laravel 中对一年中的月份进行唯一检查
- javascript - FFmpeg 实时音频编辑器
- spring-boot - 未调用订阅映射
- android - TabLayout 选项卡标题未显示在 Android Studio 中
- redis - 在 Redis 的单个命令中使用带有 TTL 的 RPUSH
- typescript - 如果我修改它的单个元素,数组不会反应
- websocket - JMeter 中的 Signalr 负载测试
- javascript - Javascript FORTNITE API 请求
- xml - 如何在 XML 中定义前缀并在 XSL 中使用它们?