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#
  4. coverting ushort to two Byte

coverting ushort to two Byte

Scheduled Pinned Locked Moved C#
questionhelp
4 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.
  • M Offline
    M Offline
    maheshfour
    wrote on last edited by
    #1

    hi I am facing a problem. i am having a ushort value (ushort val), and i want to campare it with two byte values(byte b1, b2). how can i do it? :confused: if I can convert the ushort to two seperate bytes or vice versa the problem can be solved. i.e. the ushort which is made up of two bytes is to be decomposedinto two seperate bytes thanking in anticipation mahesh

    S L E 3 Replies Last reply
    0
    • M maheshfour

      hi I am facing a problem. i am having a ushort value (ushort val), and i want to campare it with two byte values(byte b1, b2). how can i do it? :confused: if I can convert the ushort to two seperate bytes or vice versa the problem can be solved. i.e. the ushort which is made up of two bytes is to be decomposedinto two seperate bytes thanking in anticipation mahesh

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Use simple mathematics:

      byte x = 1;
      byte y = 1;
      ushort z = 257;
      if (z == (x * 256 + y))
      {// ushort equals the composition of two bytes
      }


      www.troschuetz.de

      1 Reply Last reply
      0
      • M maheshfour

        hi I am facing a problem. i am having a ushort value (ushort val), and i want to campare it with two byte values(byte b1, b2). how can i do it? :confused: if I can convert the ushort to two seperate bytes or vice versa the problem can be solved. i.e. the ushort which is made up of two bytes is to be decomposedinto two seperate bytes thanking in anticipation mahesh

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        byte hi = (byte)((val >> 8) & 0xff);
        byte lo = (byte)(val & 0xff);

        xacc-ide 0.0.10 now with C#, MSIL, C and HLSL coloring - Screenshots

        1 Reply Last reply
        0
        • M maheshfour

          hi I am facing a problem. i am having a ushort value (ushort val), and i want to campare it with two byte values(byte b1, b2). how can i do it? :confused: if I can convert the ushort to two seperate bytes or vice versa the problem can be solved. i.e. the ushort which is made up of two bytes is to be decomposedinto two seperate bytes thanking in anticipation mahesh

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

          You could also try using the System.BitConverter class. Kev

          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