Re: convert from hexadecimal to a decimal
From: Steve Kass (skass_at_drew.edu)
Date: 10/01/04
- Next message: Hugo Kornelis: "Re: convert from hexadecimal to a decimal"
- Previous message: Hugo Kornelis: "Re: convert from hexadecimal to a decimal"
- In reply to: Hugo Kornelis: "Re: convert from hexadecimal to a decimal"
- Next in thread: Hugo Kornelis: "Re: convert from hexadecimal to a decimal"
- Reply: Hugo Kornelis: "Re: convert from hexadecimal to a decimal"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 01 Oct 2004 18:10:12 -0400
You mean this isn't self-documenting? ;)
select
'0x[89abcdef]' lower, '[0-9abcdef]' upper,
0x100000000 parsename, '123456789ABCDEF' power,
cast(0 as bigint) replicate, 16. stuff,
7 charindex, 3 rtrim
into ltrim
select
b, sum(charindex(right(left(b,N),1),power)
* power(stuff,len(b)-N))
- case when lower(b) like lower+replicate(upper,charindex)
then parsename else replicate end
from T, numbers, ltrim
where n between rtrim and len(b)
group by b, lower, upper, parsename, replicate, power, charindex
go
SK
Hugo Kornelis wrote:
>On Fri, 01 Oct 2004 03:35:26 -0400, Steve Kass wrote:
>
>
>
>>Very good, and how about this?
>>
>>create function hexchar2(
>> @b varchar(10)
>>) returns int
>>as begin
>> return (
>> select
>>
>>sum((charindex(right(left(@b,N),1),'123456789ABCDEF'))*POWER(16.,len(@b)-N))
>> from numbers
>> where n between 3 and len(@b))
>> - case when lower(@b) like '0x[89abcdef]'+replicate('[0-9abcdef]',7)
>> then 0x0100000000 else cast(0 as bigint) end
>>end
>>
>>SK
>>
>>
>
>Hi Steve,
>
>Nice!
>
>With the added advantage that it can be used inline in the query, so that
>the overhad of calling a function is no longer incurred. (Though I would
>comment it if I used it in a query <g>)
>
>Best, Hugo
>
>
- Next message: Hugo Kornelis: "Re: convert from hexadecimal to a decimal"
- Previous message: Hugo Kornelis: "Re: convert from hexadecimal to a decimal"
- In reply to: Hugo Kornelis: "Re: convert from hexadecimal to a decimal"
- Next in thread: Hugo Kornelis: "Re: convert from hexadecimal to a decimal"
- Reply: Hugo Kornelis: "Re: convert from hexadecimal to a decimal"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|