久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 TSQL 解包二進制字符串

Unpacking a binary string with TSQL(使用 TSQL 解包二進制字符串)
本文介紹了使用 TSQL 解包二進制字符串的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

美好的一天,

我有許多由帶有結構的 C 應用程序創建的二進制字符串.想象一下,如果你愿意,結構看起來像這樣:

I have a number of binary strings that were created by a C app with a struct. Imagine, if you will, the struct looks like this:

 struct {
     int foo; 
     double bar; //Assume 8 bytes
     char[20] baz;
 }

每個字符串的長度為 4 + 8 + 20 = 32 個字節.字符串的結構如下所示:

Each string is 4 + 8 + 20 = 32 bytes long. The structure of the string looks something like this:

IIIIDDDDDDDDSSSSSSSSSSSSSSSSSSSS

我需要在 TSQL 存儲過程中解壓這個字符串.字符串很簡單:

I need to unpack this string in a TSQL stored proc. The string is easy:

baz = SUBSTRING(binarystring, 12, 20)

int 也是.然后通過位移轉換為整數(好吧,乘以 2^4、2^8 等)

The int also. And then convert to an integer with bit shifting (well, multiplying by 2^4, 2^8, etc)

foo_string = SUBSTRING(binarystring, 0, 4)
foo = unpack_int(foo_string)

但是,替身更具挑戰性.我可以通過遵循 IEEE754 規范來做到這一點,我對自己這樣做并不滿意.

But, the double is a lot more challenging. I am able to do it by following the IEEE754 spec, I am not happy with doing this myself.

有沒有一個函數或者什么東西可以解包 int 并從二進制字符串中加倍?

Is there a function or something that can unpack the int and double out of a binary string?

謝謝,

附言我自己從來沒有使用過 TSQL,所以上面的片段可能是非法的,但你明白了.我正在協助一位同事.

P.S. I've never used TSQL myself, so the above fragments may be illegal, but you get the notion. I'm assisting a colleague.

推薦答案

沒有內置函數可以將二進制轉換為浮點數.但是,您可以在 T-SQL 中找到用戶定義的函數來進行這種轉換,或者您可以使用 BitConverter.ToDouble(byte[]) 方法編寫一個 clr 函數來進行這種轉換.

There is no built-in function to convert from binary to float. However, you can find user-defined functions in T-SQL to do this conversion, or you can write a clr function to do this conversion using the BitConverter.ToDouble(byte[]) method.

將二進制轉換為浮點數的 t-sql 函數示例可以從 thread 在 sqlteam:

An example of a t-sql function for converting binary to float can be found from a thread at sqlteam:

CREATE FUNCTION [dbo].[fnBinaryFloat2Float]
(
    @BinaryFloat BINARY(8)
)
RETURNS FLOAT
AS
BEGIN
    RETURN  SIGN(CAST(@BinaryFloat AS BIGINT))
        * (1.0 + (CAST(@BinaryFloat AS BIGINT) & 0x000FFFFFFFFFFFFF) * POWER(CAST(2 AS FLOAT), -52))
        * POWER(CAST(2 AS FLOAT), (CAST(@BinaryFloat AS BIGINT) & 0x7ff0000000000000) / 0x0010000000000000 - 1023)
END

這篇關于使用 TSQL 解包二進制字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 国产精品中文字幕在线 | 欧美成人精品一区二区男人看 | 久久国产精品免费 | 一区日韩 | 超碰日本| 99视频免费在线 | 久久综合狠狠综合久久综合88 | 亚洲欧美日韩高清 | 中文字幕视频在线 | 成人婷婷| 日韩精品中文字幕在线 | 欧美亚洲第一区 | 91精品国产综合久久福利软件 | 一级片网站视频 | 成人免费大片黄在线播放 | 欧美精品一区在线发布 | 欧美性受xxxx白人性爽 | 请别相信他免费喜剧电影在线观看 | 一区二区三区视频在线观看 | 91成人影院 | 精品视频一区二区三区在线观看 | 国产成人精品一区二区三区网站观看 | 青青草一区 | 国产情品 | 亚洲久草 | 成年人精品视频 | 鲁一鲁资源影视 | 99国产精品99久久久久久粉嫩 | 精品视频久久久 | 国产精品一区在线观看 | 精品成人一区二区 | 久热9| h片在线免费看 | 999精品视频在线观看 | 欧美bondage紧缚视频 | www国产成人免费观看视频 | 正在播放国产精品 | 日日操夜夜操视频 | 亚洲免费人成在线视频观看 | 国产一区二区免费电影 | 亚洲一区播放 |