Re: convert from hexadecimal to a decimal
From: Steve Kass (skass_at_drew.edu)
Date: 10/01/04
- Previous message: Gary K: "Re: Select Expression Operators"
- 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 03:35:26 -0400
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
Hugo Kornelis wrote:
>On Wed, 29 Sep 2004 00:27:03 -0400, Steve Kass wrote:
>
>
>
>>This is not too efficient, but it should do the trick.
>>
>>
>
>Hi Steve,
>
>How about using a numbers table to speed it up?
>
>create function hexchar2(
> @b varchar(10)
>) returns int
>as begin
> declare @n bigint
> set @b = substring(@b,3,8)
> set @n = (select
>sum((charindex(left(right(@b,n),1),'0123456789ABCDEF')-1)*POWER(16,(n-1)))
> from dbo.numbers
> where n between 1 and len(@b))
> return
> case when @n >= 0X80000000
> then @n - 0x0100000000
> else @n end
>end
>go
>
>
>Best, Hugo
>
>
- Previous message: Gary K: "Re: Select Expression Operators"
- 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
|
|