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. Bits and bytes handling

Bits and bytes handling

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
5 Posts 4 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.
  • E Offline
    E Offline
    emrosa
    wrote on last edited by
    #1

    Hi there...I'm writing a program that will work at bits/byte level. It will accept a double number as an argument, and then the number will be decomposed in two parts: the high and the low, I'm going to do some operations with them. I know about the bitwise operators, but Is anyboady know how to make the decomposition double FUNCTION(double argument) { int hx,lx //MISSING THIS PART!!!! hx = HIGH_PART(argument); lx = LOW_PART(argument); //other operations with hx and lx // return(final_result) } Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

    J R 2 Replies Last reply
    0
    • E emrosa

      Hi there...I'm writing a program that will work at bits/byte level. It will accept a double number as an argument, and then the number will be decomposed in two parts: the high and the low, I'm going to do some operations with them. I know about the bitwise operators, but Is anyboady know how to make the decomposition double FUNCTION(double argument) { int hx,lx //MISSING THIS PART!!!! hx = HIGH_PART(argument); lx = LOW_PART(argument); //other operations with hx and lx // return(final_result) } Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      emrosa wrote: ...bits/byte level...double... Do you perchance talk about DWORD? Or do you really mean double, the extended precision floating point type? In case of DWORD, have a look at the HIWORD and LOWORD macros in MSDN.


      My opinions may have changed, but not the fact that I am right.

      1 Reply Last reply
      0
      • E emrosa

        Hi there...I'm writing a program that will work at bits/byte level. It will accept a double number as an argument, and then the number will be decomposed in two parts: the high and the low, I'm going to do some operations with them. I know about the bitwise operators, but Is anyboady know how to make the decomposition double FUNCTION(double argument) { int hx,lx //MISSING THIS PART!!!! hx = HIGH_PART(argument); lx = LOW_PART(argument); //other operations with hx and lx // return(final_result) } Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

        R Offline
        R Offline
        Roger Allen
        wrote on last edited by
        #3

        Why not use a standra C union:

        union Converter
        {
        {
        short low;
        short high;
        }
        double value;
        };

        Converter x;

        x.value = 5.67;
        short low = x.low;
        short high = x.high;

        My uinion syntax may not be correct as I have not sed them for years n years n years.... Roger Allen Sonork 100.10016 Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003

        E 1 Reply Last reply
        0
        • R Roger Allen

          Why not use a standra C union:

          union Converter
          {
          {
          short low;
          short high;
          }
          double value;
          };

          Converter x;

          x.value = 5.67;
          short low = x.low;
          short high = x.high;

          My uinion syntax may not be correct as I have not sed them for years n years n years.... Roger Allen Sonork 100.10016 Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003

          E Offline
          E Offline
          emrosa
          wrote on last edited by
          #4

          Thanks for the hint...I have already tried that and it works fine. Thanks again Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

          J 1 Reply Last reply
          0
          • E emrosa

            Thanks for the hint...I have already tried that and it works fine. Thanks again Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

            J Offline
            J Offline
            John R Shaw
            wrote on last edited by
            #5

            Your kiding me, that actualy worked? Please explane why. From MSDN: Type double Double precision values with double type have 8 bytes. The format is similar to the float format except that it has an 11-bit excess-1023 exponent and a 52-bit mantissa, plus the implied high-order 1 bit. This format gives a range of approximately 1.7E–308 to 1.7E+308 for type double. Microsoft Specific —> The double type contains 64 bits: 1 for sign, 11 for the exponent, and 52 for the mantissa. Its range is +/–1.7E308 with at least 15 digits of precision. END Microsoft Specific Ok I probubly just broke the law. But I need to know.

            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