Thread: Byte Representation

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    Byte Representation

    Does any know how to represent an int as a byte-wide variable in C. I know CHAR is byte, wide. However, I would prefer to work with int, since I can make direct hexadecimal assigments.

    OR UNLESS... can I make direct hex assigments to a char type variable?

    Such as:
    int hex;
    char ch;

    hex = 0x001A; //I know this is valid
    ch = 0x00FF; //is this valid???

    Anyone help?
    Thanks in Advance
    ~jc

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >ch = 0x00FF; //is this valid???

    You'll loose anything in the high order byte, but it'll work. While dealing with one byte chars, you'd normally do -

    ch = 0xFF;

    chars are just spaces in memory. The memory doesn't care if you're storing ASCII or a value in hex,dec, octal or any other base.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Need some help regarding data structures
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-28-2006, 05:19 AM
  4. error: identifier "byte" is undefined.
    By Hulag in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 05:46 PM
  5. sorting a structure of arrays
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 03-15-2002, 11:45 AM