Results 1 to 40 of 62

Thread: [RESOLVED] Bits, Bytes and Boomerangs (without the boomerangs...)

Threaded View

  1. #32
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Bits, Bytes and Boomerangs (without the boomerangs...)

    Quote Originally Posted by chris128 View Post
    So one thing I am still a bit puzzled about (it may just be the terminology) is bit shifting. If I can test for any individual bit being set by just using AND then why/when would I use bit shifting? Is that more for when you want to set a bit rather than just checking to see if a bit is set?
    That OPCODE is 4 bits - right? That means it's a value from 0000 (0) to 1111 (15).

    If you want to extract that value - and it's in the BYTE - you need to shift it down to position 0 and also MASK it to hide other bits that shift down with it.

    So once again - the byte with the opcode - let's say it:

    1101 0111

    The 1010 bits is the 10 values I want to extract. The decimal value of 1101 0111 is not 10 [edit - oops] - so first thing is to shift it down

    1101 0111 / 8

    0001 1010 - now the 1010 is in bit 0, bit 1, bit 2 and bit 3
    0000 1111 - this is the 15 mask

    AND these and you get

    0000 1010 - this is the 10 I want - it's in a byte - but the value of 10 (from the opcode) came through.
    Last edited by szlamany; Sep 23rd, 2009 at 06:23 PM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width