I have been task to decode a very long Hex string to decimal for further analysis. The output I'm told should be two (2) columns between 2,000 to 3,000 rows of decimals values.
My issues are the following...
1. I don't know what the split value is
2. I am told the values are 32 bit floating data array but I don't think it is.
3. The hex are supposedly 4 characters to it decimal value.
for example: 1001: 5.741E-42
4. Number 3 would only make sense if the values i'm told is 16 bit float and not 32.
I apologize in advance if this seemed confusing.
Your description is very vauge and it is hard to understand what you are after.
First: All hex numbers in your example are two bytes (it takes 2 hex digits to represent one byte).
So before you can go on, you need to know exactly how the data is formatted; is it decimal/float/... , 16 bit/32 bit/...
Since you are asking your question in this forum, I assume you are looking for a SQL solution. Based on the information in your query I just have to guess what you are after, but I will give a short sample, that might give you some direction on how the problem can be solved.
In this short example I take data stored as a SQL "binary" and spilt it in 4-byte chunks, which are then converted into float:
-- CREATE A FUNCTION TO CONVERT BINARY TO FLOAT
-- (code from: http://ask.sqlservercentral.com/questions/43447/how-do-i-convert-a-hex-to-a-floating-point-number.html)
CREATE FUNCTION dbo.fnBinaryReal2Real
) RETURNS REAL
DECLARE @Mantissa REAL,
@Real2 = CAST(2.0 AS REAL),
@IntValue = CAST(@BinaryFloat AS INT),
@Exponent = (@IntValue & 0x7f800000) / 0x00800000,
@Mantissa = 1.0 + (@IntValue & 0x007FFFFF) * POWER(@Real2, -23)
RETURN SIGN(@IntValue) * @Mantissa * POWER(@Real2, @Exponent - 127)
-- CREATE A TALLY TABLE
-- (code from: http://www.sqlservercentral.com/articles/T-SQL/62867/)
IF OBJECT_ID('dbo.Tally') IS NOT NULL
DROP TABLE dbo.Tally
--===== Create and populate the Tally table on the fly
SELECT TOP 11000 --equates to more than 30 years of dates
IDENTITY(INT,1,1) AS N
FROM Master.dbo.SysColumns sc1,
-- GET THE BINARY DATA
declare @data binary(12)
set @data = cast(0x40490FDB3FB504F342280000 as binary(12))
-- "LOOP" OVER THE BINARY STRING USING A TALLY TABLE
select dbo.fnBinaryReal2Real(substring(@data, (n-1) * 4 + 1, 4))
where n <= len(@data) / 4
Your question indicates that your data might be represented as a string. If that is the case, you can have a look att this page to see how to convert that into binary: