littleEndian /大尾端 [英] littleEndian/bigEndian

查看:78
本文介绍了littleEndian /大尾端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




因为有人从C ++那里接过C#我今天因为

我无法找到答案时偶然发现了一些事情:


我如何将具有给定endianess的字节块转换为int32而将
$ b $转换为反之?


In C ++我有这个:


#pragma intrinsic(_byteswap_ushort)

#pragma intrinsic(_byteswap_ulong)


* myword = _byteswap_ulong(mybigendianword);


导致一个精彩的单个汇编程序指令。


我发现的关于endianess的唯一文档是处理UTF8 / 16

字符串,但没有二进制文件。


有人能给我一个暗示我是如何快速执行这些事情而不是通过我自己的/>
笨拙的版本?


谢谢

doc

Hi,

as someone pulling to C# over from C++ I stumbled over something today for
which I was not able to find an answer:

HOW do I convert a byte block with a given endianess to an int32 and vice
versa?

In C++ I have this:

#pragma intrinsic(_byteswap_ushort)
#pragma intrinsic(_byteswap_ulong)

*myword = _byteswap_ulong(mybigendianword);

which results in a wonderful single assembler instruction.

The only documentation I found about endianess is on handling UTF8/16
strings, but not with binary stuff.

Can someone give me a hint how I perform such things FAST and not via my own
clumsy version?

thanks
doc

推荐答案

docschnipp写道:
docschnipp wrote:
当有人从C ++中拉到C#时我偶然发现了o我今天无法找到答案:

我如何将具有给定endianess的字节块转换为int32,反之亦然?
as someone pulling to C# over from C++ I stumbled over something today for
which I was not able to find an answer:

HOW do I convert a byte block with a given endianess to an int32 and vice
versa?




看看 http://www.pobox.com/~skeet/csharp/miscutil

特别是EndianBinaryReader / Writer和EndianBitConverter。


Jon



Have a look at http://www.pobox.com/~skeet/csharp/miscutil
In particular, the EndianBinaryReader/Writer and EndianBitConverter.

Jon


" Jon Skeet [C#MVP]"写道:
"Jon Skeet [C# MVP]" wrote:
docschnipp写道:
docschnipp wrote:
当有人从C ++中抽取C#我今天偶然发现了一些我无法找到的东西答案:

我如何将具有给定endianess的字节块转换为int32,反之亦然?
as someone pulling to C# over from C++ I stumbled over something today for
which I was not able to find an answer:

HOW do I convert a byte block with a given endianess to an int32 and vice
versa?



看看< a rel =nofollowhref =http://www.pobox.com/~skeet/csharp/miscutiltarget =_ blank> http://www.pobox.com/~skeet/csharp/miscutil
特别是,EndianBinaryReader / Writer和EndianBitConverter。



Have a look at http://www.pobox.com/~skeet/csharp/miscutil
In particular, the EndianBinaryReader/Writer and EndianBitConverter.



每隔一段时间,新闻组中的某个人就会询问一些没有的东西。框架中存在
,但我认为应该这样做。有时,我会写一些

代码给他们填补空白。


好​​吧,我觉得很完美:)


我会看看它,谢谢。


doc


"Every so often, someone on the newsgroup asks about something which doesn''t
exist in the framework, but which I think should. Sometimes, I''ll write some
code for them to plug the gap. "

Well, fits perfect I guess :)

I''ll take a look into it, thanks.

doc


Hello docschnipp,


这就是我目前的情况使用(在VB中):


公共函数ReadBigEndianInt32()作为Int32

Dim tReturn As Int32 = 0

Dim tBuffer(3)As Byte


oStream.Read(tBuffer,0,tBuffer.Length)


Array.Reverse(tBuffer)

tReturn = BitConverter.ToInt32(tBuffer,0)


返回tReturn


结束功能


和写作课程相反..


-Boo
Hello docschnipp,

Here''s what I currently use (in VB):

Public Function ReadBigEndianInt32() As Int32

Dim tReturn As Int32 = 0
Dim tBuffer(3) As Byte

oStream.Read(tBuffer, 0, tBuffer.Length)

Array.Reverse(tBuffer)
tReturn = BitConverter.ToInt32(tBuffer, 0)

Return tReturn

End Function

And the inverse of course for Writing..

-Boo

<有人从C ++那里接过C#我今天偶然发现了一些我无法找到答案的东西:

我如何转换具有给定endianess的字节块到int32和
反之亦然?

在C ++中我有这个:

#pragma intrinsic(_byteswap_ushort)
#pragma intrinsic(_byteswap_ulong)
* myword = _byteswap_ulong(mybigendianword);

这会产生一个很棒的单曲汇编指令。

关于endianess的唯一文档是处理UTF8 / 16
字符串,但不是二进制文件。

有人可以给我一个提示我如何快速地执行这些事情而不是通过我自己的笨拙版本?

感谢
doc
Hi,

as someone pulling to C# over from C++ I stumbled over something today
for which I was not able to find an answer:

HOW do I convert a byte block with a given endianess to an int32 and
vice versa?

In C++ I have this:

#pragma intrinsic(_byteswap_ushort)
#pragma intrinsic(_byteswap_ulong)
*myword = _byteswap_ulong(mybigendianword);

which results in a wonderful single assembler instruction.

The only documentation I found about endianess is on handling UTF8/16
strings, but not with binary stuff.

Can someone give me a hint how I perform such things FAST and not via
my own clumsy version?

thanks
doc



这篇关于littleEndian /大尾端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆