北京软件公司面试题

thanksfriend 2008-09-22 11:33:21
byte[] header = new byte[24]{0,0,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
long dataAreaLength = BitConverter.ToInt32(header,4);
long contentLength = BitConverter.ToInt32(header, 8);
long nextRecordStartPosition = BitConverter.ToInt64(header, 12);


dataAreaLength =0
contentLength =16842752
nextRecordStartPosition =72340172838076673

你知道是怎么算出来的吗?
...全文
220 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
梦想家起飞 2008-09-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jjkk168 的回复:]
比较烦这种高台跳水但实用性并不强,貌似体现了面试官的技术,实际是面试官的弱智行为的面试题
[/Quote]

感觉这个问题很基础啊,不搞清楚的话很多字节和二进制存储层面的东西理解不了的。
梦想家起飞 2008-09-23
  • 打赏
  • 举报
回复
public static int ToInt32(
byte[] value,
int startIndex
)

参考BitConverter.ToInt32方法的声明,简单地说,
就是从一个字节数组里面从索引指定的位置开始读入
4个字节的数据,并转换成Int32。要注意的是,实际
转换的时候,字节顺序是与声明的时候相反的,所以要
倒过来看。(Little-Endian的字节顺序)

参考MSDN的例子:
// Example of the BitConverter.ToInt32 method.
using System;

class BytesToInt32Demo
{
const string formatter = "{0,5}{1,17}{2,15}";

// Convert four byte array elements to an int and display it.
public static void BAToInt32( byte[ ] bytes, int index )
{
int value = BitConverter.ToInt32( bytes, index );

Console.WriteLine( formatter, index,
BitConverter.ToString( bytes, index, 4 ), value );
}

// Display a byte array, using multiple lines if necessary.
public static void WriteMultiLineByteArray( byte[ ] bytes )
{
const int rowSize = 20;
int iter;

Console.WriteLine( "initial byte array" );
Console.WriteLine( "------------------" );

for( iter = 0; iter < bytes.Length - rowSize; iter += rowSize )
{
Console.Write(
BitConverter.ToString( bytes, iter, rowSize ) );
Console.WriteLine( "-" );
}

Console.WriteLine( BitConverter.ToString( bytes, iter ) );
Console.WriteLine( );
}

public static void Main( )
{
byte[ ] byteArray = {
15, 0, 0, 0, 0, 128, 0, 0, 16, 0,
0, 240, 255, 0, 202, 154, 59, 0, 54, 101,
196, 241, 255, 255, 255, 127 };

Console.WriteLine(
"This example of the BitConverter.ToInt32( byte[ ], " +
"int ) \nmethod generates the following output. It " +
"converts elements \nof a byte array to int values.\n" );

WriteMultiLineByteArray( byteArray );

Console.WriteLine( formatter, "index", "array elements",
"int" );
Console.WriteLine( formatter, "-----", "--------------",
"---" );

// Convert byte array elements to int values.
BAToInt32( byteArray, 1 );
BAToInt32( byteArray, 0 );
BAToInt32( byteArray, 21 );
BAToInt32( byteArray, 6 );
BAToInt32( byteArray, 9 );
BAToInt32( byteArray, 13 );
BAToInt32( byteArray, 17 );
BAToInt32( byteArray, 22 );
BAToInt32( byteArray, 2 );
}
}

/*
This example of the BitConverter.ToInt32( byte[ ], int )
method generates the following output. It converts elements
of a byte array to int values.

initial byte array
------------------
0F-00-00-00-00-80-00-00-10-00-00-F0-FF-00-CA-9A-3B-00-36-65-
C4-F1-FF-FF-FF-7F

index array elements int
----- -------------- ---
1 00-00-00-00 0
0 0F-00-00-00 15
21 F1-FF-FF-FF -15
6 00-00-10-00 1048576
9 00-00-F0-FF -1048576
13 00-CA-9A-3B 1000000000
17 00-36-65-C4 -1000000000
22 FF-FF-FF-7F 2147483647
2 00-00-00-80 -2147483648
*/



  • 打赏
  • 举报
回复
[Quote=引用楼主 thanksfriend 的帖子:]
byte[] header = new byte[24]{0,0,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
long dataAreaLength = BitConverter.ToInt32(header,4);
long contentLength = BitConverter.ToInt32(header, 8);
long nextRecordStartPosition = BitConverter.ToInt64(header, 12);


dataAreaLength =0
contentLength =16842752
nextRecordStartPosition =72340172838076673…
[/Quote]
非常赞同...
梦想家起飞 2008-09-23
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 vrhero 的回复:]
从这个题来看...这个公司的产品很可能和TCP通信或COM通信关系密切...

ps:看不懂这种题的明显基础不够...
[/Quote]

有可能。用.net做TCP通信的话,使用BitConverter几乎是必然。
我们是前一阵子做swf文件格式解析的时候使用过,
BitConverter这个类,比较常用于二进制数据解析,
一般的Web应用或者管理系统几乎不用,它们主要和DB打交道。
vrhero 2008-09-23
  • 打赏
  • 举报
回复
从这个题来看...这个公司的产品很可能和TCP通信或COM通信关系密切...

ps:看不懂这种题的明显基础不够...
benbenkui 2008-09-23
  • 打赏
  • 举报
回复
同意楼主的看法,我也不会,也在北京,也在找工作
yslan 2008-09-23
  • 打赏
  • 举报
回复
考试的时候准许GOOGLE 百度么?
shadowjl 2008-09-23
  • 打赏
  • 举报
回复
不会
sharpblade 2008-09-23
  • 打赏
  • 举报
回复
不知道,真的不知道.........
等下,我google,baidu一下.......
flylovejings 2008-09-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jjkk168 的回复:]
比较烦这种高台跳水但实用性并不强,貌似体现了面试官的技术,实际是面试官的弱智行为的面试题
[/Quote]

呵呵
有同感,一点技术也不沾边,就一计算,这方法不知道做web的有人用么!!

写了递归都比这强!
还想懒够 2008-09-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wingtrace 的回复:]
引用 1 楼 jjkk168 的回复:
比较烦这种高台跳水但实用性并不强,貌似体现了面试官的技术,实际是面试官的弱智行为的面试题


感觉这个问题很基础啊,不搞清楚的话很多字节和二进制存储层面的东西理解不了的。
[/Quote]

我并不是说这个不基础,但实际作用呢?我有时候去面试别人的时候,我很少出这样的题目,一般就只看对方的思路,思路吻合了,其他的都好办,如果只是懂语法但不知道如何应用,这似乎有点脱离招人的本意了
还想懒够 2008-09-22
  • 打赏
  • 举报
回复
比较烦这种高台跳水但实用性并不强,貌似体现了面试官的技术,实际是面试官的弱智行为的面试题

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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