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. General Programming
  3. C / C++ / MFC
  4. converting byte to bit

converting byte to bit

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsdata-structureshelptutorial
4 Posts 3 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.
  • A Offline
    A Offline
    Arrun
    wrote on last edited by
    #1

    Hi I am doing a project in image processing using MFC. GetBitmapBits() stores the pixel value in a BYTE array. It works fine with 8 bits bitmap, but when working with 4 bits bitmap, it combines 2 pixel values and stores in the BYTE array. How to overcome this problem

    C 1 Reply Last reply
    0
    • A Arrun

      Hi I am doing a project in image processing using MFC. GetBitmapBits() stores the pixel value in a BYTE array. It works fine with 8 bits bitmap, but when working with 4 bits bitmap, it combines 2 pixel values and stores in the BYTE array. How to overcome this problem

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Use && and || to combine and mask values, instead of + or =. For example, FF && F0 == F0. If you take an 8 bit number and set it to equal itself && 15, you get only the low four bits, && 240 gives you the high four. In that way, you can set one pixel to zero. Then if you want to set the pixel in the low four bits, you just put oldVal || newval, that copies it in. to copy into the high four, do this: oldval || ( newVal << 4). this shifts the values up four bits first. To just set two pixels do this (pixelLeft << 4) + pixelRight. You can use plus here, because you're replacing both values. Christian Graus - Microsoft MVP - C++

      PJ ArendsP 1 Reply Last reply
      0
      • C Christian Graus

        Use && and || to combine and mask values, instead of + or =. For example, FF && F0 == F0. If you take an 8 bit number and set it to equal itself && 15, you get only the low four bits, && 240 gives you the high four. In that way, you can set one pixel to zero. Then if you want to set the pixel in the low four bits, you just put oldVal || newval, that copies it in. to copy into the high four, do this: oldval || ( newVal << 4). this shifts the values up four bits first. To just set two pixels do this (pixelLeft << 4) + pixelRight. You can use plus here, because you're replacing both values. Christian Graus - Microsoft MVP - C++

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        Close, but not quite. The operators he wants are | and & (bitwise operators as opposed to logical operators). See http://www.codeproject.com/cpp/bitbashing.asp[^]

        Within you lies the power for good; Use it!

        C 1 Reply Last reply
        0
        • PJ ArendsP PJ Arends

          Close, but not quite. The operators he wants are | and & (bitwise operators as opposed to logical operators). See http://www.codeproject.com/cpp/bitbashing.asp[^]

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Dagnamit. Sorry. :-O Christian Graus - Microsoft MVP - C++

          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