Results 1 to 10 of 10

Thread: Converting a numerical char array to a long?

Threaded View

  1. #2
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    How about:
    Code:
    unsigned char x[3];        // unsigned char is a 8-bit value on 8051 
    x[0] = 0x02;
    x[1] = 0xFF;
    x[2] = 0xFF;
    
    unsigned long i = 0;
    for (int index = 0; index < 3; index++)
    {
        i <<= 8;
        i |= x[index];
    }
    
    // or
    
    unsigned long i = x[0];
    i = i << 8;
    i = i | x[1];
    i = i << 8;
    i = i | x[2];
    Last edited by jlou; Aug 16th, 2003 at 05:33 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
  •  



Click Here to Expand Forum to Full Width