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. BYTE to binary conversion

BYTE to binary conversion

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
4 Posts 4 Posters 1 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
    Madan Chauhan
    wrote on last edited by
    #1

    Hi all, if I have BYTE bTemp = 0xAB; I need the binary stream of this BYTE value(ie 010101011) in to an integer Array. Is there any short way to do that rather to write the code to convert it? Thanks M Chauhan

    K E 2 Replies Last reply
    0
    • M Madan Chauhan

      Hi all, if I have BYTE bTemp = 0xAB; I need the binary stream of this BYTE value(ie 010101011) in to an integer Array. Is there any short way to do that rather to write the code to convert it? Thanks M Chauhan

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      use memcpy but be aware of data size types.

      Press F1 for help or google it. Greetings from Germany

      R 1 Reply Last reply
      0
      • M Madan Chauhan

        Hi all, if I have BYTE bTemp = 0xAB; I need the binary stream of this BYTE value(ie 010101011) in to an integer Array. Is there any short way to do that rather to write the code to convert it? Thanks M Chauhan

        E Offline
        E Offline
        Eugen Podsypalnikov
        wrote on last edited by
        #3

        Try it :) :

        void TranslateBits(CArray<int>* pcArray, BYTE* pbyData, size_t cbDataSize)
        {
        if (pcArray && pbyData && cbDataSize) {
        for (int i = 0; i < cbDataSize; i++) {
        BYTE byData = pbyData[i];
        for (int j = 0; j < 8; j++) {
        int iBit = byData & 1;
        byData >> 1;
        pcArray->Add(iBit);
        }
        }
        }
        }

        void Usage()
        {
        BYTE byData(0xAB);
        CArray<int> cBitsArray;
        TranslateBits(&cBitsArray, &byData, sizeof(byData));
        }

        virtual void BeHappy() = 0;

        1 Reply Last reply
        0
        • K KarstenK

          use memcpy but be aware of data size types.

          Press F1 for help or google it. Greetings from Germany

          R Offline
          R Offline
          r ps
          wrote on last edited by
          #4

          I think you misunderstood the question. memcpy will not help the OP in this case!

          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