Results 1 to 5 of 5

Thread: Bitwise operations

  1. #1
    Aragorn
    Guest

    Bitwise operations

    Ho can I check if the most (or least) significant bit of a value is set?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    low bit

    x & 1

    hi bit

    x & y

    or to return a value 1 or 0

    x >> z

    where
    z=(sizeof(x)-1)*8
    and
    y is 2^z
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Aragorn
    Guest

    thanks

    That will do.
    Thanks kedaman.


  4. #4
    Aragorn
    Guest

    Question ¿¿??

    I took a closer look at it and came up with this

    z=sizeof(x)*8 - 1
    rather than what you wrote.
    I'll assume this is what you meant.
    thanks anyway; I got the idea.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    yeah that's it
    x was of course meant to be the type of x, but since you got the idea, everythign is the compiler may or may not optimize it though, so you'd better evaluate z
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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