Thread: about byte datatype

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    3

    Exclamation about byte datatype

    I want to know whether there is a datatype called byte in C.
    If there plese explain me with a simple example

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    A byte is eight bits of memory, there is no generic byte type. Although, a char is a byte so I guess you could use that if the data can be expressed in a numerical form.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    not an official one, anyway, but most declare it as:

    typedef unsigned char byte;
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Yeah a char will preform as a good way to store a byte. If you are coming from Java, or ever go to Java, I learned the hard way do not use chars to store bytes heh.

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    An unsigned character is a BYTE. (0->255)
    A signed character is a BYTE. (-128->127)

    Only difference is the range of values you can express within 8 bits in signed and unsigned. For signed, 1 bit is used as the sign bit and thus you lose how many values can be represented since you have 1 less bit.

    Windows defines byte exacly as Sebastiani has shown.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I want to know whether there is a datatype called byte in C.
    No, but the char data type is directly equivalent to the smallest addressable unit on the machine. Essentially it's a byte. If you really want the name, you can do this:
    Code:
    typedef unsigned char byte;
    typedef signed char sbyte;
    >A byte is eight bits of memory
    Not necessarily. A byte could be any number of bits greater than or equal to 8 (since that's a hard minimum required by C), even though a "byte" usually means an octet on most modern systems. It's better to think of a byte as the generic term for the smallest addressable unit on the machine than as a concrete data type with a set size.

    >An unsigned character is a BYTE. (0->255)
    That's assuming an 8-bit range.

    >A signed character is a BYTE. (-128->127)
    That's assuming an 8-bit range and two's complement signed representation. Both of which may not be the case. I don't recall the harish13 mentioning a specific system, and C is very generic. So you would be better off saying:

    An unsigned char is a byte. At least 0->255.
    A signed char is a byte. At least -127->127

    My best code is written with the delete key.

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Yeah yeah u just eternally confuzzled the OP. LOL

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. How to Convert a byte datatype to char or string
    By kvp_vivek in forum C Programming
    Replies: 3
    Last Post: 06-17-2006, 02:20 PM
  4. Need some help regarding data structures
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-28-2006, 05:19 AM
  5. error: identifier "byte" is undefined.
    By Hulag in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 05:46 PM