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. How split up a double value into 8 sets of uint8

How split up a double value into 8 sets of uint8

Scheduled Pinned Locked Moved C / C++ / MFC
help
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.
  • C Offline
    C Offline
    cahit23
    wrote on last edited by
    #1

    Hi all, i am working on a simulink model (graphical block programming) and in a block i am supposed to write a user defined function (S-Function) which takes a double value and outputs 8 uint8 values. It has some simulink related commands but basically C Code. Since i have an error message, i would like to share it with you all to find a way out. #define S_FUNCTION_NAME double2integer #define S_FUNCTION_LEVEL 2 #include "simstruc.h" typedef union { uint8_T uvalue[8]; real_T d; //real_T is double } UnionNum; static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDataType(S, 0, SS_DOUBLE); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S,1)) return; ssSetOutputPortWidth(S, 0, 8); ssSetOutputPortDataType(S, 0, SS_UINT8); ssSetNumSampleTimes(S, 1); ssSetOptions(S,0); } static void mdlOutputs(SimStruct *S, int_T tid) { int_T i; int_T width = ssGetOutputPortWidth(S,0); InputPtrsType uPtrs = ssGetInputPortSignalPtrs(S,0); uint8_T *y = (uint8_T *)ssGetOutputPortSignal(S,0); UnionNum num; num.d = *uPtrs[0] ; for(i=0; i

    D T 2 Replies Last reply
    0
    • C cahit23

      Hi all, i am working on a simulink model (graphical block programming) and in a block i am supposed to write a user defined function (S-Function) which takes a double value and outputs 8 uint8 values. It has some simulink related commands but basically C Code. Since i have an error message, i would like to share it with you all to find a way out. #define S_FUNCTION_NAME double2integer #define S_FUNCTION_LEVEL 2 #include "simstruc.h" typedef union { uint8_T uvalue[8]; real_T d; //real_T is double } UnionNum; static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDataType(S, 0, SS_DOUBLE); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S,1)) return; ssSetOutputPortWidth(S, 0, 8); ssSetOutputPortDataType(S, 0, SS_UINT8); ssSetNumSampleTimes(S, 1); ssSetOptions(S,0); } static void mdlOutputs(SimStruct *S, int_T tid) { int_T i; int_T width = ssGetOutputPortWidth(S,0); InputPtrsType uPtrs = ssGetInputPortSignalPtrs(S,0); uint8_T *y = (uint8_T *)ssGetOutputPortSignal(S,0); UnionNum num; num.d = *uPtrs[0] ; for(i=0; i

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      cahit23 wrote:

      Error : Have illegal types 'double' and 'void'

      Do you not think it pertinent to include the line number of the code this error refers to? We're not mind readers.:rolleyes:


      "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

      "Judge not by the eye but by the heart." - Native American Proverb

      C 1 Reply Last reply
      0
      • C cahit23

        Hi all, i am working on a simulink model (graphical block programming) and in a block i am supposed to write a user defined function (S-Function) which takes a double value and outputs 8 uint8 values. It has some simulink related commands but basically C Code. Since i have an error message, i would like to share it with you all to find a way out. #define S_FUNCTION_NAME double2integer #define S_FUNCTION_LEVEL 2 #include "simstruc.h" typedef union { uint8_T uvalue[8]; real_T d; //real_T is double } UnionNum; static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDataType(S, 0, SS_DOUBLE); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S,1)) return; ssSetOutputPortWidth(S, 0, 8); ssSetOutputPortDataType(S, 0, SS_UINT8); ssSetNumSampleTimes(S, 1); ssSetOptions(S,0); } static void mdlOutputs(SimStruct *S, int_T tid) { int_T i; int_T width = ssGetOutputPortWidth(S,0); InputPtrsType uPtrs = ssGetInputPortSignalPtrs(S,0); uint8_T *y = (uint8_T *)ssGetOutputPortSignal(S,0); UnionNum num; num.d = *uPtrs[0] ; for(i=0; i

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        cahit23 wrote:

        How split up a double value into 8 sets of uint8

        use this :

        union DoubleToBytes {
        double _d;
        uint8 _ui[8];
        };


        TOXCCT >>> GEII power

        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

        1 Reply Last reply
        0
        • D David Crow

          cahit23 wrote:

          Error : Have illegal types 'double' and 'void'

          Do you not think it pertinent to include the line number of the code this error refers to? We're not mind readers.:rolleyes:


          "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

          "Judge not by the eye but by the heart." - Native American Proverb

          C Offline
          C Offline
          cahit23
          wrote on last edited by
          #4

          DavidCrow wrote:

          Do you not think it pertinent to include the line number of the code this error refers to? We're not mind readers.

          Oh sorry, pointed lines are : real_T d; and ** real_T is the representation of double in this format, even if i write there 'double' appears again as error ** num.d = *uPtrs[0]; Thank you for your consideration! Cahit

          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