I couldn't find any references to bitshifting in SQL BOL (v7), so I
assume that you can't do it. Also I can't find either the & operator or
the POWER function in the standard so I guess they are SQL Server
specific. I don't know if that is an issue.
regards
David Cameron
nOw.b2b
dcameron@i...
> -----Original Message-----
> From: David Cameron
> Sent: Wednesday, 19 March 2003 5:54 PM
> To: sql language
> Subject: [sql_language] RE: Binary - string mainpulation
>
>
> That is an interesting problem. The best I have been able to
> think of is to use a bitmask (well hexmask I guess) and AND them.
>
> So in this case you want to & with 15.
> ie
> 0x00200
> & 0x0000F
> =3D 0x00000
>
> and
>
> 0x00202
> & 0x0000F
> =3D 0x00002
>
> I was trying to come up with anther example of this for
> cutting out a value from the middle of the hex number, this
> is the first time I have tried to use bitmasks in hex and my
> head started to hurt so I stopped. Anyway this works for what
> you want.
>
> Actually I've just worked out what was wrong. The mask needs
> to be be F for the value you want. Eg suppose you have a hex value of:
> 0xFD103 and want the third last value (1)
>
> the mask then should be
> 0x00F00 =3D 3840
>
> anding the two together gives
> 0x00100
>
> Of course now you need to get the value. I haven't checked to
> see if SQL has a shift function (<< and >> in C), but to do
> it without shift:
> 0x00100 / POWER(16, 2) =3D 1
>
> Check it out:
> PRINT (1036547 & 3840) / (POWER(16,2))
>
> I always wondered if the time I spent on Assembler would be
> useful for anything.
>
> regards
> David Cameron
> nOw.b2b
> dcameron@i...
>
> > -----Original Message-----
> > From: Haslett, Andrew [mailto:andrew.haslett@i...]
> > Sent: Wednesday, 19 March 2003 5:25 PM
> > To: sql language
> > Subject: [sql_language] RE: Binary - string mainpulation
> >
> >
> > I realise I didn't explain that too well, so I'll give it
> another try:
> >
> > I'm pulling some data from an LDAP server (Active Directory)
> > of which one
> > attribute (UserAccountControl) is a hex number. One part of
> > this hex number
> > indicates whether that account is disabled or not.
> >
> > Now, when pulling the data through LDAP it is returned as an
> > integer. I need
> > to decide if that integer represents whether the user account
> > is disabled or
> > not.
> >
> > An example, I retrieve the following two integers and convert
> > them to hex
> > (VarBinary):
> > 512 -> 0x00200 (account is enabled)
> > 514 -> 0x00202 (account is disabled)
> >
> > So basically the last (hex) digit indicates whether the user
> > is enabled or
> > disabled. (0-enabled, 2-disabled).
> >
> > I have no troubles converting the initial integer to hex
> > format (CAST to
> > varbinary) however I can't seem to grab the last character
> > (using SUBSTRING
> > OR RIGHT) and then convert it a character so as to do a comparison.
> >
> > Basically I wish to do a CASE on the last digit to return the string
> > 'ENABLED' or 'DISABLED'..
> >
> > Cheers,
> > Andrew
> >
> > -----Original Message-----
> > From: Haslett, Andrew [mailto:andrew.haslett@i...]
> > Sent: Wednesday, 19 March 2003 4:42 PM
> > To: sql language
> > Subject: [sql_language] Binary - string mainpulation
> >
> >
> > Hi all.
> >
> > I have a decimal number, which once converted to binary (or
> > hexadecimal),
> > I'd like to test the rightmost character.
> >
> > For example:
> > Decimal: 66050
> > Converted to Hex (varbinary): 0x10202
> >
> > I'd like to grab (convert) the rightmost character (the 2) so
> > as to be able
> > to do a comparison.
> >
> > The problem is that whenever I try to grab that character it
> > is either blank
> > or shown as some other collation or something..
> >
> > I've tested all types of CAST's according to BOL but Im now stumped!
> >
> > Any ideas?
> >
> > Thanks,
> > Andrew
> >
> >
> >
> > IMPORTANT - PLEASE READ ********************
> > This email and any files transmitted with it are
> confidential and may
> > contain information protected by law from disclosure.
> > If you have received this message in error, please notify
> the sender
> > immediately and delete this email from your system.
> > No warranty is given that this email or files, if attached to this
> > email, are free from computer viruses or other defects. They
> > are provided on the basis the user assumes all responsibility for
> > loss, damage or consequence resulting directly or indirectly from
> > their use, whether caused by the negligence of the sender or not.
> >
> >
> > IMPORTANT - PLEASE READ ********************
> > This email and any files transmitted with it are
> confidential and may
> > contain information protected by law from disclosure.
> > If you have received this message in error, please notify
> the sender
> > immediately and delete this email from your system.
> > No warranty is given that this email or files, if attached to this
> > email, are free from computer viruses or other defects. They
> > are provided on the basis the user assumes all responsibility for
> > loss, damage or consequence resulting directly or indirectly from
> > their use, whether caused by the negligence of the sender or not.
> >
> >
>
>