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. Managed C++/CLI
  4. How to send double value as 8 uint8 values??

How to send double value as 8 uint8 values??

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestiondata-structurestutorial
3 Posts 2 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 currently working on Serial Interface between a control box and PC and want to send/receive double values from Pc to the box as 8 uint8 values since the box only accepts in uint8 form. For that i thought as follows : to get that double value (64 bits) in binary form and get the last 8 bits with &(and) operator and shifting bits to right till all bits are finished,namely : double var; char var2send[8]; % in array var2send[0]= var & 0x00000000000000ff % last 8 bits with & operator var>>8; %shifting bits var2send[1]= var & 0x00000000000000ff var>>8; . . % and sending this array as output . But in this code, i received an error that says i cant use double with & operators so that must be converted 64 bit long form!! How can i manage to do this?? or anyone has better way or suggestion? I hope i could clearly explain my problem. I would be very pleased if you could help me! Thanks a lot! Cahit

    C 1 Reply Last reply
    0
    • C cahit23

      Hi all, I am currently working on Serial Interface between a control box and PC and want to send/receive double values from Pc to the box as 8 uint8 values since the box only accepts in uint8 form. For that i thought as follows : to get that double value (64 bits) in binary form and get the last 8 bits with &(and) operator and shifting bits to right till all bits are finished,namely : double var; char var2send[8]; % in array var2send[0]= var & 0x00000000000000ff % last 8 bits with & operator var>>8; %shifting bits var2send[1]= var & 0x00000000000000ff var>>8; . . % and sending this array as output . But in this code, i received an error that says i cant use double with & operators so that must be converted 64 bit long form!! How can i manage to do this?? or anyone has better way or suggestion? I hope i could clearly explain my problem. I would be very pleased if you could help me! Thanks a lot! Cahit

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Yes, binary operations only work with integers. Multiply by whatever number of decimals you want, then cast to int. BTW, this is the wrong forum, this is not a managed C++ question

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      C 1 Reply Last reply
      0
      • C Christian Graus

        Yes, binary operations only work with integers. Multiply by whatever number of decimals you want, then cast to int. BTW, this is the wrong forum, this is not a managed C++ question

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

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

        oh sorry, i deliver my message in visual c++ forum then!

        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