Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. Bitwise Operators

Bitwise Operators

Scheduled Pinned Locked Moved IT & Infrastructure
c++questiontutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Milan Zdimal
    wrote on last edited by
    #1

    Just wanted to ask if anyone has any good online reading info on bitwise operators. I am kind of new to c++ and programming all together and these bitwise operators are causing some serious "illegal operations" :eek: to occur in my brain. Specifically, I am having trouble understanding an example (from Ivor Hortin's Beginning Visual C++ 6, Pg. 1074) which divides a number by eight and calculates the remainder using bitwise operators: 29 = (3x8) +5 29 = 0000 0000 0001 1101 7 = 0000 0000 0000 0111 ========================= 0000 000 0000 0101 = rem 5 My question is how would one figure out that they needed to use the binary of the number 7 to divide by eight? I hope this makes sense. Thanks

    J 1 Reply Last reply
    0
    • M Milan Zdimal

      Just wanted to ask if anyone has any good online reading info on bitwise operators. I am kind of new to c++ and programming all together and these bitwise operators are causing some serious "illegal operations" :eek: to occur in my brain. Specifically, I am having trouble understanding an example (from Ivor Hortin's Beginning Visual C++ 6, Pg. 1074) which divides a number by eight and calculates the remainder using bitwise operators: 29 = (3x8) +5 29 = 0000 0000 0001 1101 7 = 0000 0000 0000 0111 ========================= 0000 000 0000 0101 = rem 5 My question is how would one figure out that they needed to use the binary of the number 7 to divide by eight? I hope this makes sense. Thanks

      J Offline
      J Offline
      Jon Sagara
      wrote on last edited by
      #2

      If you shift a binary number to the left by 1 bit, you are effectively diving that number by two (2^1 = 2). 0000 0000 0001 1101 = 29 Shift left by three bits (2^3 = 8, so we're dividing by 8): 0000 0000 0000 0011 -> 101 (101 are the three bits shifted out. I suppose this is the remainder. 101 binary also equals 5 decimal.) 0000 0000 0000 0011 = 3 0000 0000 0000 0101 = 5 In regular division: 29 / 8 = 3 rem 5, so the result is correct. I'm not sure where the 7 came from, though. These are just my observations. I don't know if this is mathematically correct. Perhaps one of our resident math majors can prove this for you. :) [EDIT] Sorry, I don't have any good online resources for reading about bitwise operators. I think the best thing you can do is to study the binary number system. [/EDIT] Jon Sagara What about :bob:? Sonork ID: 100.9999 jonsagara

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups