Thread: Byte Array / Integer conversion

  1. #1
    Registered User
    Join Date
    May 2008

    Byte Array / Integer conversion


    I'm working on an application that needs to convert an array of four hex bytes i.e. 'A1 B2 C3 D4' into an integer (in that case 2712847316). I also have to do this in the other direction (integer into 4 bytes). It doesn't need to come out as hex, I just need to maintain the overall 32 bit data value and split it into 4 bytes.

    I'm afraid I'm a little stuck (haven't programmed for a few years) and could do with some help.

    It may be useful for you to know that this is being written as an 'S-Function' in Matlab so does not work as a 'standard' C code, essentially I'd prefer not to have to do the conversion in a seperate function / procedure but do everything in the main().

    Thank you for your interest,


  2. #2
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    I am not too familiar with MATLAB, but iirc, 4 byte integers at least in my architecture can be stored as unsigned long variables. What data types are available for you in MATLAB.

  3. #3
    Registered User
    Join Date
    May 2008
    Pretty much all the data types that available in C.

    Matlab provides an mex C compiler and you write everything as if it was regular C (if there is such a thing, I'm a bit of a newbie). The only difference is that the main() is executed afresh on each time step of the matlab model so static variables must be used to avoid losing data between steps. Aside from that it is C.

    Really I'm confused as how I can split my integer value into 4 bytes?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Converting character array to integer array
    By quiet_forever in forum C++ Programming
    Replies: 5
    Last Post: 04-02-2007, 05:48 AM
  3. Need some help regarding data structures
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-28-2006, 05:19 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM