Re: Converting hex number to integer
From: Steve Kass (skass_at_drew.edu)
Date: 03/30/04
- Next message: Guy Brom: "localization issue and defaults"
- Previous message: Miroo_news: "Re: Table Naming and Keywords"
- In reply to: Francois Piette: "Re: Converting hex number to integer"
- Next in thread: SriSamp: "Re: Converting hex number to integer"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 30 Mar 2004 08:57:50 -0500
Francois,
I don't know what message you are referring to - the first message in
this thread didn't mention the version of SQL Server you are using.
In any case, you can leave out the collate clause if your server is
case-insensitive, and you can try replacing cast(... as bigint) with
convert(decimal(10), ...). I don't know exactly which features don't
exist in 6.5.
SK
Francois Piette wrote:
>My SQL version (6.5) doesn't understand "collate" nor cast.
>Have you seen my message with the actual SQL request ?
>
>
>--
>francois.piette@overbyte.be
>Author of ICS (Internet Component Suite, freeware)
>Author of MidWare (Multi-tier framework, freeware)
>http://www.overbyte.be
>
>
>"Steve Kass" <skass@drew.edu> a écrit dans le message de
>news:efZAFkiFEHA.2408@TK2MSFTNGP10.phx.gbl...
>
>
>> Here is a somewhat obscure solution that works for up to 8 hex digits
>>
>>
>and
>
>
>>assumes 2's complement representation. There are many ways of doing this,
>>and if you search groups.google.com for sqlserver+hex+string+convert I
>>
>>
>think
>
>
>>you'll find some others.
>>
>>create table T (
>> h varchar(10)
>>)
>>insert into T values ('0X34fd1022')
>>insert into T values ('0X5000')
>>insert into T values ('0Xffff')
>>insert into T values ('0X80000000')
>>go
>>
>>
>>select h,
>> - len(h)/10*patindex('%[89ABCDEF]%' collate Latin1_General_CI_AS
>>,substring(h,2,2))/2 * power(2.,32) +
>> cast(sum(charindex(substring(h,N,1),'123456789ABCDEF' collate
>>Latin1_General_CI_AS) * power(16.,len(h)-N))
>> as bigint) as n
>>from T, (
>> select 3 as N union all select 4 union all select 5 union all
>> select 6 union all select 7 union all select 8 union all
>> select 9 union all select 10
>>) N
>>where N <= len(h)
>>group by h
>>
>>go
>>
>>drop table T
>>
>>-- Steve Kass
>>-- Drew University
>>-- Ref: 65F00CE1-CC26-4E04-8690-87A81AC1DA20
>>
>>Francois Piette wrote:
>>
>>
>>
>>>I would like to convert a string representing an hex number to an
>>>integer.Unfortunately the CONVERT function doesn't like CHAR or VARCHAR.
>>>
>>>SELECT CONVERT(INT, 0x1AB2) works very well but
>>>SELECT CONVERT(INT, "0x1AB2") gives an error message.
>>>
>>>btw: In my real problem, "0x1AB2" comes from a SUBSTRING applied to a
>>>
>>>
>column
>
>
>>>value.
>>>
>>>Any idea ?
>>>
>>>--
>>>francois.piette@overbyte.be
>>>Author of ICS (Internet Component Suite, freeware)
>>>Author of MidWare (Multi-tier framework, freeware)
>>>http://www.overbyte.be
>>>
>>>
>>>
>>>
>>>
>>>
>
>
>
>
- Next message: Guy Brom: "localization issue and defaults"
- Previous message: Miroo_news: "Re: Table Naming and Keywords"
- In reply to: Francois Piette: "Re: Converting hex number to integer"
- Next in thread: SriSamp: "Re: Converting hex number to integer"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|