Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

So many ways to define a byte

Tags:

People also ask

How do you define bytes?

byte, the basic unit of information in computer storage and processing. A byte consists of 8 adjacent binary digits (bits), each of which consists of a 0 or 1. (Originally, a byte was any string of more than one bit that made up a simple piece of information like a single character.

How many different types of bytes are there?

The eight different types of bytes currently used in computer architectures range from kilobytes (1,024 bytes) to yottabytes (1,024 zettabytes). Byte multiples can be measured using two systems: base-2 or base-10. A base-2, or binary, system is commonly expressed as a rounded off decimal number.

Why is a byte 255 and not 256?

A byte is a group of 8 bits. A bit is the most basic unit and can be either 1 or 0. A byte is not just 8 values between 0 and 1, but 256 (28) different combinations (rather permutations) ranging from 00000000 via e.g. 01010101 to 11111111 . Thus, one byte can represent a decimal number between 0(00) and 255.


Does it make a difference which one I use in objective-c (particularly on iOS)? I assume it comes from inheriting from C and its types, as well as inheriting the types from Mac OS, which iOS was based on, but I don't know which one I should use:

unsigned char from...well..the compiler?

uint8_t from stdint.h

UInt8 from MacTypes.h

Byte from MacTypes.h

Bytef from zconf.h

I am aware that the various defs are for portability reasons, and using literals like unsigned char is not good future thinking (size might change, and things will end up like the Windows API again). I'd like some advice on how to spot the best ones for my uses. Or a good tongue lashing if I'm just being silly...

EDIT : Just for some more info, if I want something that will always be 1 byte, should I use uint8_t (doesn't seem like it would change with a name like that)? I'd like to think UInt8 wouldn't change either but I see that the definition of UInt32 varies on whether or not the processor is 64-bit.

FURTHER EDIT : When I say byte, I specifically mean that I want 8 bits. I am doing pixel compression operations (32 bits -> 8 bits) for disk storage.