How do you convert an integer to two bytes in C#?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: How do you convert an integer to two bytes in C#?

  1. #1
    Join Date
    Dec 2005
    Posts
    134

    How do you convert an integer to two bytes in C#?

    How do you convert an integer to two bytes in C#?

    I have googled around but no answer really works. At least none I found.

  2. #2
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    Google is useless

    Code:
    int i;
    byte b1;
    byte b2;
    
    i = 512;
    b1 = (byte)(i/256);
    b2 = (byte)(i % 256); // % is the modulo operator (remainder)
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

Similar Threads

  1. Replies: 1
    Last Post: 09-21-2010, 09:01 AM
  2. plesae help me i will cry
    By stone cold in forum VB Classic
    Replies: 6
    Last Post: 12-22-2006, 11:49 AM
  3. Replies: 3
    Last Post: 04-08-2006, 06:38 PM
  4. Physical Address of the NIC
    By eduardoms in forum Security
    Replies: 2
    Last Post: 05-06-2005, 10:26 AM
  5. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 10:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center