-1

How to get unsigned short (always 16 bit, machine byte order) binary string in c# from integer?

Number can be from 1 to 65000.

CroMagnon
  • 1,218
  • 7
  • 20
  • 32
  • 3
    Please read [ask] and show some example input and output, as well as what you have tried. What is a binary string anyway? Which bits do you want to use from the 32-bit integer? (How) do you want to handle overflow? – CodeCaster Nov 21 '17 at 11:10

1 Answers1

1

I could not get exactly what you need but a simple cast could do this.

static void Main()
        {
            int i = 50;

            ushort short_val = (ushort)i;
            uint uint_val = (uint)i;
            Console.WriteLine(uint_val);
            Console.ReadLine();
        }
Vicky
  • 2,027
  • 1
  • 19
  • 31
  • _"I could not get exactly what you need"_ - then post a comment, not an answer. – CodeCaster Nov 21 '17 at 11:29
  • I thought this is what Op asked but seeing his rating,i was adamant to believe that this is what he could really asked.Still ,advice accepted and will take care in future :) – Vicky Nov 21 '17 at 12:04