What's the difference between a word and byte?

后端 未结 14 2045
再見小時候
再見小時候 2020-12-12 09:50

I\'ve done some research. A byte is 8 bits and a word is the smallest unit that can be addressed on memory. The exact length of a word varies. What I don\'t understand is wh

相关标签:
14条回答
  • 2020-12-12 10:00

    BYTE

    I am trying to answer this question from C++ perspective.

    The C++ standard defines ‘byte’ as “Addressable unit of data large enough to hold any member of the basic character set of the execution environment.”

    What this means is that the byte consists of at least enough adjacent bits to accommodate the basic character set for the implementation. That is, the number of possible values must equal or exceed the number of distinct characters. In the United States, the basic character sets are usually the ASCII and EBCDIC sets, each of which can be accommodated by 8 bits. Hence it is guaranteed that a byte will have at least 8 bits.

    In other words, a byte is the amount of memory required to store a single character.

    If you want to verify ‘number of bits’ in your C++ implementation, check the file ‘limits.h’. It should have an entry like below.

    #define CHAR_BIT      8         /* number of bits in a char */
    

    WORD

    A Word is defined as specific number of bits which can be processed together (i.e. in one attempt) by the machine/system. Alternatively, we can say that Word defines the amount of data that can be transferred between CPU and RAM in a single operation.

    The hardware registers in a computer machine are word sized. The Word size also defines the largest possible memory address (each memory address points to a byte sized memory).

    Note – In C++ programs, the memory addresses points to a byte of memory and not to a word.

    0 讨论(0)
  • 2020-12-12 10:05

    If a machine is byte-addressable and a word is the smallest unit that can be addressed on memory then I guess a word would be a byte!

    0 讨论(0)
  • 2020-12-12 10:07

    Byte: Today, a byte is almost always 8 bit. However, that wasn't always the case and there's no "standard" or something that dictates this. Since 8 bits is a convenient number to work with it became the de facto standard.

    Word: The natural size with which a processor is handling data (the register size). The most common word sizes encountered today are 8, 16, 32 and 64 bits, but other sizes are possible. For examples, there were a few 36 bit machines, or even 12 bit machines.

    The byte is the smallest addressable unit for a CPU. If you want to set/clear single bits, you first need to fetch the corresponding byte from memory, mess with the bits and then write the byte back to memory.

    The word by contrast is biggest chunk of bits with which a processor can do processing (like addition and subtraction) at a time. That definition is a bit fuzzy, as some processor might have different word sizes for different tasks (integer vs. floating point processing for example). The word size is what the majority of operations work with.

    There are also a few processors who have a different pointer size: for example, the 8086 is a 16-bit processor which means its registers are 16 bit wide. But its pointers (addresses) are 20 bit wide and were calculated by combining two 16 bit registers in a certain way.

    0 讨论(0)
  • 2020-12-12 10:08

    Reference:https://www.os-book.com/OS9/slide-dir/PPT-dir/ch1.ppt

    The basic unit of computer storage is the bit. A bit can contain one of two values, 0 and 1. All other storage in a computer is based on collections of bits. Given enough bits, it is amazing how many things a computer can represent: numbers, letters, images, movies, sounds, documents, and programs, to name a few. A byte is 8 bits, and on most computers it is the smallest convenient chunk of storage. For example, most computers don’t have an instruction to move a bit but do have one to move a byte. A less common term is word, which is a given computer architecture’s native unit of data. A word is made up of one or more bytes. For example, a computer that has 64-bit registers and 64- bit memory addressing typically has 64-bit (8-byte) words. A computer executes many operations in its native word size rather than a byte at a time. Computer storage, along with most computer throughput, is generally measured and manipulated in bytes and collections of bytes. A kilobyte, or KB, is 1,024 bytes a megabyte, or MB, is 1,024 2 bytes a gigabyte, or GB, is 1,024 3 bytes a terabyte, or TB, is 1,024 4 bytes a petabyte, or PB, is 1,024 5 bytes Computer manufacturers often round off these numbers and say that a megabyte is 1 million bytes and a gigabyte is 1 billion bytes. Networking measurements are an exception to this general rule; they are given in bits (because networks move data a bit at a time)

    0 讨论(0)
  • 2020-12-12 10:10

    Why not say 8 bits?

    Because not all machines have 8-bit bytes. Since you tagged this C, look up CHAR_BIT in limits.h.

    0 讨论(0)
  • 2020-12-12 10:10

    A word is the size of the registers in the processor. This means processor instructions like, add, mul, etc are on word-sized inputs.

    But most modern architectures have memory that is addressable in 8-bit chunks, so it is convenient to use the word "byte".

    0 讨论(0)
提交回复
热议问题