Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. BIt Shift Error
Forum Updated to NodeBB v4.3 + New Features

BIt Shift Error

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 1.8k Views
  • 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
    akshay123
    wrote on last edited by
    #1

    Hi all ,

    i am developing an application where i need to shift the bit values .

    quint64 bit_values;
    
    int num=1;
    
    bit_values = num<<42;
    

    So the output of bit_values is 1024. This output is wrong .the correct output must be 4398046511104 . After analysing i came to know that . QT Compiler is of 32bit .

    I tried to split 64bit values to two 32 bit values . but it failing . Please help me to resolve this issue

    Thanks

    jsulmJ 1 Reply Last reply
    0
    • A akshay123

      Hi all ,

      i am developing an application where i need to shift the bit values .

      quint64 bit_values;
      
      int num=1;
      
      bit_values = num<<42;
      

      So the output of bit_values is 1024. This output is wrong .the correct output must be 4398046511104 . After analysing i came to know that . QT Compiler is of 32bit .

      I tried to split 64bit values to two 32 bit values . but it failing . Please help me to resolve this issue

      Thanks

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @akshay123 num is an int (32bit) that is the problem: you're shifting a 32bit int by 42 positions, this causes an overflow. Change num to quint64 and it will work.

      Note: there is no such thing as "Qt compiler".

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • A Offline
        A Offline
        akshay123
        wrote on last edited by
        #3

        Thanks @jsulm . As you have specifed i have changed it to uint64 . now tried to shift the values . but the result is same

        jsulmJ 1 Reply Last reply
        0
        • A akshay123

          Thanks @jsulm . As you have specifed i have changed it to uint64 . now tried to shift the values . but the result is same

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @akshay123 I tried and it works:

          quint64 bit_values;
          quint64 num = 1;
          bit_values = num<<42;
          qDebug() << bit_values;
          

          Can you show your code?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • A Offline
            A Offline
            akshay123
            wrote on last edited by akshay123
            #5
            QList<quint64> temp_Shifted_values;
                quint64 tempValue=0;
                quint64 megaValue=0;
                for(int i=0; i< bit_Value.count(); i++)                  //bit values is a function parameter
                {
                    tempValue = bit_Value.at(i) <<  bit_Low_Value.at(i);
            
                    temp_Shifted_values.append(tempValue);
                }
                for(int i=0; i< temp_Shifted_values.count(); i++)
                {
                    megaValue = megaValue | temp_Shifted_values.at(i);
                }
            

            i am using ```
            qt-opensource-windows-x86-mingw48_opengl-5.2.1

            jsulmJ 1 Reply Last reply
            0
            • A akshay123
              QList<quint64> temp_Shifted_values;
                  quint64 tempValue=0;
                  quint64 megaValue=0;
                  for(int i=0; i< bit_Value.count(); i++)                  //bit values is a function parameter
                  {
                      tempValue = bit_Value.at(i) <<  bit_Low_Value.at(i);
              
                      temp_Shifted_values.append(tempValue);
                  }
                  for(int i=0; i< temp_Shifted_values.count(); i++)
                  {
                      megaValue = megaValue | temp_Shifted_values.at(i);
                  }
              

              i am using ```
              qt-opensource-windows-x86-mingw48_opengl-5.2.1

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @akshay123 What is the type of bit_Value ?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                akshay123
                wrote on last edited by
                #7

                the type of bit value is int

                jsulmJ 1 Reply Last reply
                0
                • A akshay123

                  the type of bit value is int

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @akshay123 So, you again do the same mistake: int is 32bit

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • A Offline
                    A Offline
                    akshay123
                    wrote on last edited by
                    #9

                    @jsulm Thanks . Sorry for the that . Since code size is very big . i didnt noticed . Thanks for your help

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved