16 bit word

This is a discussion on 16 bit word within the C Programming forums, part of the General Programming Boards category; Hi I was wondering if there is (or how i would make) a 16 bit signed word, data type in ...

  1. #1
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168

    16 bit word

    Hi I was wondering if there is (or how i would make) a 16 bit signed word, data type in C?

    I read that int16_t was C's 16bit signed word but i tried this code and it didnt work:

    Code:
    int16_t Data4[1][4];
    Data4[0][0]=5;
    Is this wrong? How do I go about making this data type (if int16_t doesnt really exist)?

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,159
    You have to figure out which data type is appropriate for your specific compiler. It's not the same everywhere, but in many cases, "short int" is what you want.

    The C99 header stdint.h defines a bunch of standard types like this, if you can use it.

  3. #3
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    hmmm.. im using Visual C++ 6, as part of Visual Studios.
    The program executed fine but i dont know that it worked.

    if anyone else has suggestions i would be grateful since i dont know if this one worked or not.

    well i need this... i think its the same thing. sorry i was confused.
    word - 16 bit integer
    thanks it still doesnt work but the error might lie here...
    Binary File - Byte order / endian
    Last edited by chico1st; 08-08-2007 at 03:53 PM.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you are using visual studio, a 16-bit "word" IS "short" or "unsigned short" (optionally followed by "int", but it's not necessary).

    There's plenty of include-files that define this in a variety of ways, but I haven't got VC6 on my machine, so I can't say which ones do there...

    Not sure why you think this has anything to do with endian-ness of the machine... Or are you just linking your different questions to get more visitors?

    --
    Mats

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    WORD is defined in windows.h

    Alternately you can do:

    typedef unsigned short WORD;


    I do not mind a typedef like this because as this relates to the actual assembly data types a WORD is always 16 bits regardless if the CPU is 32 or 64 bits. It also makes it a bit simpler if you are going to write assembly routines to interface with your C code since the data type is staring you in the face.

  6. #6
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    ok cool, yeah ill do that type def thing.

    Im not trying to increase visitors matsp. This binary file im making, has this endian-ness and the 16bit integer.
    This binary file has to be processed by another file. The binary file i currently produce cant be proccessed by the other file which doesnt tell me why it doesnt work. ( I didnt make it )

    So I think it is one of the two errors. all i know is that the file doesnt go in.

  7. #7
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    What do u get when you try to read the file through one more program. What is that you can see? are u able to get something out of the file. It would be more better if you could show us some of your code.

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. counting 16 bit number from a buffer
    By baccardi in forum C Programming
    Replies: 4
    Last Post: 02-20-2009, 02:28 PM
  2. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  3. Using 'if' with char arrays or string objects
    By c++_n00b in forum C++ Programming
    Replies: 36
    Last Post: 06-06-2002, 09:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21