Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Casting to and from Binary ?

Status
Not open for further replies.

AnStr

Technical User
Feb 25, 2002
3
DE
Hello,

I want to increment a hex number by 8 (given as String in @strVar1).
Casting hex numbers seems impossible to mee, since I did not succeed with the following statements:

set @strVar1 = '3b24a3b81c'
set @binVar1 = cast ('0x' + @strVar1 as binary)
set @IntVar1 = cast (@binVar1 as integer)

print '@strVar1= ' + '@binVar1= ' + '@IntVar1= '
print '@strVar1= ' + @strVar1
print @binVar1
print @IntVar1

set @IntVar2 = @IntVar1 + 8
set @binVar2 = cast (@IntVar2 as binary)
set @strVar2 = cast (@binVar2 as char)

print '@strVar2= ' + '@binVar2= ' + '@IntVar2= '
print @IntVar2
print @binVar2
print "@strVar2= " + @strVar2

----- the results are: -------------------------------

@strVar1= @binVar1= @IntVar1=
@strVar1= 3b24a3b81c
0x30 ... I would expect 0x3b24a3b81c
48 ... OK
@strVar2= @binVar2= @IntVar2=
56 ... OK
0x00 ... I would expect 0x38
@strVar2= ... I would expect @strVar2= 0x00

Can anyone explain what happens or give a hint
for a better solution ?

AnStr

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top