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. Bit concatenation in C++

Bit concatenation in C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structuresquestion
6 Posts 5 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
    Manoj7390
    wrote on last edited by
    #1

    hi guys.. I have written the below code in C. I have 3 bits in three different integer variables. How can I concatenate those values assuring that i need only binary values (1/0).

    #include <stdio.h>
    #include "manojturbo5.h"
    #include "bitsconv.h"
    #include "manojencoder2.h"

    void main()
    {
    int message,interleaver,u,p,q,r,final,result,i;

    printf("Enter the message\n");
    scanf("%d",&message);

    bitconv (message);
    for(r=0;r<32;r++)
    {
    u = array[31-r];
    p = encoder(array[31-r]);
    q = encoder2(array[31-r]);

    printf("%d\t %d\t %d\n",u,p,q);
    }
    return;
    }

    F S L 3 Replies Last reply
    0
    • M Manoj7390

      hi guys.. I have written the below code in C. I have 3 bits in three different integer variables. How can I concatenate those values assuring that i need only binary values (1/0).

      #include <stdio.h>
      #include "manojturbo5.h"
      #include "bitsconv.h"
      #include "manojencoder2.h"

      void main()
      {
      int message,interleaver,u,p,q,r,final,result,i;

      printf("Enter the message\n");
      scanf("%d",&message);

      bitconv (message);
      for(r=0;r<32;r++)
      {
      u = array[31-r];
      p = encoder(array[31-r]);
      q = encoder2(array[31-r]);

      printf("%d\t %d\t %d\n",u,p,q);
      }
      return;
      }

      F Offline
      F Offline
      Freak30
      wrote on last edited by
      #2

      Do you really think you will get any different answers than here[^], which you all didn't seem to like?

      M 1 Reply Last reply
      0
      • F Freak30

        Do you really think you will get any different answers than here[^], which you all didn't seem to like?

        M Offline
        M Offline
        Manoj7390
        wrote on last edited by
        #3

        I cannot use shifting operator because it will give numbers other than 1/0. If I shift it once i will get 2. I dont want that. I need only binary (1/0).

        C 1 Reply Last reply
        0
        • M Manoj7390

          hi guys.. I have written the below code in C. I have 3 bits in three different integer variables. How can I concatenate those values assuring that i need only binary values (1/0).

          #include <stdio.h>
          #include "manojturbo5.h"
          #include "bitsconv.h"
          #include "manojencoder2.h"

          void main()
          {
          int message,interleaver,u,p,q,r,final,result,i;

          printf("Enter the message\n");
          scanf("%d",&message);

          bitconv (message);
          for(r=0;r<32;r++)
          {
          u = array[31-r];
          p = encoder(array[31-r]);
          q = encoder2(array[31-r]);

          printf("%d\t %d\t %d\n",u,p,q);
          }
          return;
          }

          S Offline
          S Offline
          SoMad
          wrote on last edited by
          #4

          I was reading the previous thread and I think the problem you are having is understanding the difference between storing the values and using the values. Richard showed you how to pack the three binary values into a single integer:

          int Answer = (u << 2) | (p << 1) | q

          That is for storing them. Don't worry about the actual value of Answer. When you need to use the binary values, you have to unpack them. There are different ways to do it, but I think this method is the easiest way for you to understand it:

          q = Answer & 1;
          p = (Answer >> 1) & 1;
          u = (Answer >> 2) & 1;

          Soren Madsen

          "When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty

          1 Reply Last reply
          0
          • M Manoj7390

            hi guys.. I have written the below code in C. I have 3 bits in three different integer variables. How can I concatenate those values assuring that i need only binary values (1/0).

            #include <stdio.h>
            #include "manojturbo5.h"
            #include "bitsconv.h"
            #include "manojencoder2.h"

            void main()
            {
            int message,interleaver,u,p,q,r,final,result,i;

            printf("Enter the message\n");
            scanf("%d",&message);

            bitconv (message);
            for(r=0;r<32;r++)
            {
            u = array[31-r];
            p = encoder(array[31-r]);
            q = encoder2(array[31-r]);

            printf("%d\t %d\t %d\n",u,p,q);
            }
            return;
            }

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            There are so many things wrong with this piec of code, I suggest you go back to your reference manual and read about types, variables and functions. And work through a lot of the samples.

            Use the best guess

            1 Reply Last reply
            0
            • M Manoj7390

              I cannot use shifting operator because it will give numbers other than 1/0. If I shift it once i will get 2. I dont want that. I need only binary (1/0).

              C Offline
              C Offline
              Chris Losinger
              wrote on last edited by
              #6

              Manoj7390 wrote:

              I cannot use shifting operator because it will give numbers other than 1/0.

              that makes no sense at all.

              Manoj7390 wrote:

              If I shift it once i will get 2.

              1 = 00000001 (in binary) 1 << 1 = 2 2 = 00000010 (in binary) you might benefit from reading about binary math and how computers store numbers.

              image processing toolkits | batch image processing

              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