What's the difference between a word and byte?
Asked Answered
G

14

131

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 what's the point of having a byte? Why not say 8 bits?

I asked a prof this question and he said most machines these days are byte-addressable, but what would that make a word?

Goree answered 13/10, 2011 at 6:17 Comment(5)
It is best to avoid the term "word" because of its ambiguity. Or make it precise by saying 16-bit word, 32-bit word, ...Kiddush
Is it advantageous to have a word be larger or smaller?Goree
@quest4knoledge a larger word allows for larger pointers (a.k.a more RAM), and allows for bigger numbers to be processed quickly. It also may allows for some operations like memset to be faster, by working in larger blocks. However, processors with a larger word require more transistors in the processor and may consume a bit more energy.Winnipegosis
@Winnipegosis and a larger word would mean smaller address space, or am I confused?Goree
To answer the question "what is the point of having a byte" - it's history. CPU's did not start out being able to handle anything bigger than a "byte" (earlier processors handled only nybbles (4 bits) but the term never really caught on). The first cpu of any note was the Intel 8086/8088. It was designed to deal with instructions built around "bytes", this is also why we still refer to memory in terms of xBytes e.g. GigaBytes because the basic unit of addressable memory was the byte. 'K is a reference to KiloBytes of which the first PC's had 16, expandable to 64 - woo hoo!Oliverolivera
S
226

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.

By contrast, one definition for word is the biggest chunk of bits with which a processor can do processing (like addition and subtraction) at a time – typically the width of an integer register. That definition is a bit fuzzy, as some processors might have different register sizes for different tasks (integer vs. floating point processing for example) or are able to access fractions of a register. The word size is the maximum register size that the majority of operations work with.

There are also a few processors which 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.


In some manuals and APIs, the term "word" may be "stuck" on a former legacy size and might differ from what's the actual, current word size of a processor when the platform evolved to support larger register sizes. For example, the Intel and AMD x86 manuals still use "word" to mean 16 bits with DWORD (double-word, 32 bit) and QWORD (quad-word, 64 bit) as larger sizes. This is then reflected in some APIs, like Microsoft's WinAPI.

Slung answered 13/10, 2011 at 6:51 Comment(25)
Excellent answer. I'd only quibble with "[t]he word by contrast is biggest chunk of bits with which a processor can do processing ... at a time". It is in fact the most-common chunk of bits etc. Lots of architectures that have evolved over time have a word size that isn't their widest, but they are often limited in what they can do with their widest values.Telephonic
For extra credit, a "nibble" is a common term for half a byte. It arose during the early microcomputer CPU era (e.g., the Intel 8080), and was always understood to be 4 bits, because by then the byte had settled down to 8 bits.Telephonic
Today a 8-bit byte is a standard; see IEC 80000-13:2008.Offload
Is there such a name for a 2-Word length memory?Pedro
to dark and @RossPatterson So if we use the old definition of byte, how big is it on an 8086? 8088? and suppose there a particular cpu that is only 1 byte long and would byte be the size of that one CPU?Andresandresen
@barlop: Which "old definition of byte" do you mean? On both 8086 and 8088 the byte is 8 bit wide (as was already the de facto standard back then) and the word size is 16 bit. The major difference between the two is that the data bus is 16 bit wide for the 8086 and 8 bit wide for the 8088. A CPU where most registers are 8-bit wide do have a word-size of 8-bit (or 1 byte). Famous examples would be the Intel 8080 or Z80 (even though both have limited support for 16 bit operations; these work by combining two 8-bit registers).Slung
@Slung i'm not totally clear on what the old definition of byte was, but it meant that it isn't necessarily 8 bits. The 8086 and 8088 both have 16bit word size, so 16 bit general purpose registers. Memory locations no doubt 8 bits. Given that, Is the old definition of byte, that it meant "memory location size" or, more accurately, and for the rare case of variable length memory locations, the smallest possible memory location size?Andresandresen
@barlop: There is no "old" definition: since its introduction it's simply the smallest unit in a computer architecture, apart from the bit. Most often, that means the smallest addressable unit (or memory location size).Slung
@Slung when you say memory location, are you considering cpu registers to be memory locations? so if a cpu register was smaller than a ram-memory location, then would you say byte was the size of that small addressable cpu register?Andresandresen
@barlop: No, a register is not a memory location. And a CPU with a register size smaller than the smallest addressable memory size doesn't make sense, does it? I'm afraid this is degenerating into a chat, so if things are still unclear, please post a new question instead.Slung
@DebanjanDhar: Yes, they're unrelated. The only relation is that a page is (AFAIK) always a multiple of the word size.Slung
x86 (as usual) makes things complicated: In Intel terminology, a word is 16 bits, even on modern x86 CPUs where the default operand size is 32 bits (dword), and the integer register width is 64 bits (qword). And xmm registers are 128-bits wide (movdqa move double-quad). The memory bus is at least 64 bits wide (and transfers in bursts of 64 bytes = a cache line), and execution-unit to cache paths are at least 128 bits wide, or 256 or even 512 bits wide. Whatever the native machine-word size of modern x86 is, it's not 16 bits, but modern x86 still uses 8086 terminology.Rechaba
@Puck: double-word is the standard term. e.g. DWCAS (double-word compare-and-swap) in architecture-neutral lockless programming terminology. And most architectures that have been extended at least once have "double-word" versions of instructions. e.g. MIPS64 daddu (double-word add unsigned). On x86, a dword is 32 bits, half of the max register width, because x86 started with 16-bit 8086 and now has 64-bit wide quad-word registers and memory operand-sizes mov qword [rdi], 12345. (An x86 qword is the same width as a MIPS / PowerPC doubleword, because of terminology, see prev comment).Rechaba
larggest chunk of bits with which a processor can do processing -> that mean word == the size of register?Zanthoxylum
@Crystina: Yes, more specifically: it's usually the size of the general purpose registers (registers for floating point may have a different size, for example).Slung
Re: my earlier comments. Another way to look at it is that "word size" isn't a useful term for modern x86. It implies that a bunch of things all care about the same specific size, but there isn't a single natural "machine word" on x86-64. The register width is also (usually) the pointer width, but that's about all. (64-bit RISC ISAs also usually keep their terminology of a word being 32-bit, and still the instruction size, so e.g. MIPS has ld (load double-word) and dsll to double-word left-shift.)Rechaba
I made some edits to this, trying to preserve the simplistic definitions of the original (register width vs. "most common" operation size) while adding some caveats / context. (And correcting mistakes like saying that FP registers might have a different word size, rather than saying they might be multiple words). Definitely some of the origin of the term "word" comes from machine-code instruction formats which on classic RISCs are also single words. Some ISAs are more heavily word-oriented than others, e.g. x86 isn't, with byte-stream machine code and supporting any power of 2 operand-size.Rechaba
@PeterCordes: Thanks, but I feel it added too many (unnecessary) details which made the answer harder to understand so I rolled it back. But you had a good point about the "word" in manuals/APIs and I've added a brief addendum about that. If you still feel that the answer in its current form is wrong or missing an important clarification, please feel free to edit again.Slung
Like I said in the changelog and comment, "different word sizes for different tasks (integer vs. floating point processing for example)" is just plain wrong. I don't think that's standard terminology at all. (Although it would arguably apply with your made-up definition of "word size" which doesn't match normal usage that I'm familiar with.) Many of the other changes you rolled back were important, not just the one you added a footnote about. It's going to be hard for me to edit your answer in a way you like if we seriously disagree about what "word" means, or that it's always definable.Rechaba
Also I find it weird that you wrote "especially Microsoft" when the question is tagged [assembly] and [cpu-architecture]. (And formerly [hardware] before I retagged to [word] and [byte].) Intel's and AMD's manuals use those terms to document the assembly language and architecture. Microsoft does actually use those as type names in their WinAPI C headers, but that's a downstream consequence of them originally caring about the API from an assembly-language perspective back in the day, I assume (early Windows 1.0).Rechaba
@PeterCordes: I guess I understand where some of the confusion came from: I used "word" in a context that should've read "register" and tried to further improve the answer using some of the infos you've provided before. I agree that "word" is not always well-definable, and it's sometimes even just a marketing term. My goal here is to give a useful definition without getting lost in too many details. Since you know a lot more about x86 details in particular (haven't done assembly-level programming in over a decade) and other interesting stuff, why not add another answer?Slung
Looking at this again, I think your edits are good. There are kind of two separate concepts: the CPU-architecture concept of a machine word, like (integer) register width, a concept which has gotten less useful as micorarchitectures have gotten wider data paths than they need for pointers. (e.g. SIMD, and stuff like AArch64's ability to load 16 bytes into a pair of integer regs with ldp, and it's handled as a single 16-byte atomic load if it's aligned on ARMv8.4 I think.) vs. the technical terminology in manuals and asm syntax like MIPS64 lw (32-bit) vs. ld (64-bit double-word)Rechaba
As you say, as architectures have evolved, these terms have diverged, with the programming / type-width meaning staying the same for source compatibility, but most 64-bit ISAs still using "word" for 32-bit. (Or even 16-bit for x86, as in movzx eax, word [rdi], or paddw (packed SIMD add of 16-bit integer elements).Rechaba
Re: posting my own answer: I've posted answers on What's the size of a QWORD on a 64-bit machine? (including an argument that "word size" as a CPU-architecture concept doesn't fit modern x86, there isn't a single width used everywhere.) And Weird data sizes? / What comes after QWORD? / How can Microsoft say the size of a word in WinAPI is 16 bits?Rechaba
How many bits does a WORD contain in 32/64 bit OS respectively? is good, too, starting by explicitly making the distinction between WORD as a type name in Windows vs. CPU-architecture concepts, and fixed-width meanings in assembly.Rechaba
T
18

What I don't understand is what's the point of having a byte? Why not say 8 bits?

Apart from the technical point that a byte isn't necessarily 8 bits from a historical perspective, the reasons for having a term is simple human nature:

  • economy of effort (aka laziness) - it is easier to say "byte" rather than "eight bits"

  • tribalism - groups of people like to use jargon / a private language to set them apart from others.

Just go with the flow. You are not going to change 50+ years of accumulated IT terminology and cultural baggage by complaining about it.


The technically correct term to use when you mean "8 bits independent of the hardware architecture" is octet.

Tailback answered 13/10, 2011 at 6:47 Comment(2)
i thought the octet was just the french translation of the byte, thank you ;)Capillarity
It might have started out as that. (I'm not a native French speaker.) But now "octet" has a specific meaning in technical IT English as well. (Note: that in English "octet" also means a group of 8 musicians, or a musical composition for 8 players. In English, words often have may meanings.)Tailback
H
11

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.

Herringbone answered 29/5, 2012 at 18:12 Comment(0)
A
7

It seems all the answers assume high level languages and mainly C/C++.

But the question is tagged "assembly" and in all assemblers I know (for 8bit, 16bit, 32bit and 64bit CPUs), the definitions are much more clear:

byte  = 8 bits 
word  = 2 bytes
dword = 4 bytes = 2Words (dword means "double word")
qword = 8 bytes = 2Dwords = 4Words ("quadruple word")
Allocation answered 3/2, 2013 at 18:38 Comment(5)
Nope, these sizes are only valid on a 16-bit machine. You're probably used to Windows programming which still uses these macros as it's a legacy from its 16-bit days and MS hasn't bothered to correct this.Slung
BTW, because the size of a word (and really even a byte) can vary, ISO-C has the int<X>_t and uint<X>_t types (plus more) which should be used if you want a variable/parameter of a specific bit size.Slung
@Slung we are talking about assembly language here. C standards are not relevant. BTW, I am programming assembly from 1980 and the same names was in use. (well, maybe except qword)Allocation
However, I did find an exception: in GNU as, the .word may be 32 bits (for example for Sparc).Slung
Sorry, AS is not an assembler. It is an ugly, cripple, miserable, mutant, created with the only goal to be a back end for the HLL compilers.Allocation
W
6

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.

Walt answered 13/10, 2011 at 6:19 Comment(0)
W
6

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".

Winnipegosis answered 13/10, 2011 at 6:21 Comment(5)
So in a sense the term "byte" is just used for convenience?Goree
Yes, "byte" was especially convenient when the term was invented. Like many conventions, once they set in they persist. I'm not sure if byte-based terminology really makes computers any easier to understand in the big picture anymore, but it's the dominant convention and isn't like to change any time soon.Winnipegosis
Byte is the term used for a unit that was used as a character in text. Historically there were byte with sizes from 6 to 9 bits.Kiddush
@Kiddush how is it possible that a char takes up less room than a word?Goree
@ quest4knoledge: because memory is stored in smaller chunks that words. A word is 32bits (or 64bits on newer machines). In an algorithm that processes individual chars 1-by-1, they DO take up a whole word only when inside the CPU, and when placed back in RAM, they are packed more tightly.Winnipegosis
B
5

In this context, a word is the unit that a machine uses when working with memory. For example, on a 32 bit machine, the word is 32 bits long and on a 64 bit is 64 bits long. The word size determines the address space.

In programming (C/C++), the word is typically represented by the int_ptr type, which has the same length as a pointer, this way abstracting these details.

Some APIs might confuse you though, such as Win32 API, because it has types such as WORD (16 bits) and DWORD (32 bits). The reason is that the API was initially targeting 16 bit machines, then was ported to 32 bit machines, then to 64 bit machines. To store a pointer, you can use INT_PTR. More details here and here.

Bagley answered 13/10, 2011 at 6:39 Comment(0)
F
4

The exact length of a word varies. What I don't understand is what's the point of having a byte? Why not say 8 bits?

Even though the length of a word varies, on all modern machines and even all older architectures that I'm familiar with, the word size is still a multiple of the byte size. So there is no particular downside to using "byte" over "8 bits" in relation to the variable word size.

Beyond that, here are some reasons to use byte (or octet1) over "8 bits":

  1. Larger units are just convenient to avoid very large or very small numbers: you might as well ask "why say 3 nanoseconds when you could say 0.000000003 seconds" or "why say 1 kilogram when you could say 1,000 grams", etc.
  2. Beyond the convenience, the unit of a byte is somehow as fundamental as 1 bit since many operations typically work not at the bit level, but at the byte level: addressing memory, allocating dynamic storage, reading from a file or socket, etc.
  3. Even if you were to adopt "8 bit" as a type of unit, so you could say "two 8-bits" instead of "two bytes", it would often be very confusing to have your new unit start with a number. For example, if someone said "one-hundred 8-bits" it could easily be interpreted as 108 bits, rather than 800 bits (one-hundred 8-bits is 100 times 8 bits).

1 Although I'll consider a byte to be 8 bits for this answer, this isn't universally true: on older machines a byte may have a different size (such as 6 bits. Octet always means 8 bits, regardless of the machine (so this term is often used in defining network protocols). In modern usage, byte is overwhelmingly used as synonymous with 8 bits.

Frau answered 10/2, 2018 at 22:17 Comment(0)
B
2

A group of 8 bits is called a byte ( with the exception where it is not :) for certain architectures )

A word is a fixed sized group of bits that are handled as a unit by the instruction set and/or hardware of the processor. That means the size of a general purpose register ( which is generally more than a byte ) is a word

In the C, a word is most often called an integer => int

Bochum answered 13/10, 2011 at 6:23 Comment(3)
A group of 8 bits is called an octet.Walt
correct: The term octet was defined to explicitly denote a sequence of 8 bits because of the ambiguity associated with the term byte. But I like the sound of byte better :)Bochum
@tolitius: +1 for "But I like the sound of byte better": I strongly suspect you're not alone in this and safe for a few niche systems, the "confusion" of a byte possibly being a size other than 8-bit is no longer relevant these days.Rebec
B
1

Whatever the terminology present in datasheets and compilers, a 'Byte' is eight bits. Let's not try to confuse enquirers and generalities with the more obscure exceptions, particularly as the word 'Byte' comes from the expression "By Eight". I've worked in the semiconductor/electronics industry for over thirty years and not once known 'Byte' used to express anything more than eight bits.

Bonita answered 3/2, 2013 at 18:4 Comment(3)
Unusual yes(we know that. An example is, The texas instruments c54x Google texas instruments c54x byte. ti.com/lit/ug/spru393/spru393.pdf "The ’C55x instructions are variable byte lengths ranging in size from 8 bits to 48 bits." #2098649Andresandresen
It doesn't come from there at all. The term was actually coined by W. Buchholtz at IBM in the late 1950's. Source: bobbemer.com/BYTE.HTM. According to Bob Bemer, the spelling "byte" was chosen in preference to "bite" to avoid confusion (with "bit") due to typos. He would know. He was there!Tailback
(Only 30 years? You are a mere whipper-snapper. I learned to program on systems where the natural "byte" size was not 8 bits :-) )Tailback
W
0

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)

Warfold answered 13/4, 2020 at 9:0 Comment(0)
D
-1

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!

Duenna answered 13/10, 2011 at 6:19 Comment(2)
Yep. The minimum addressable unit of memory on TMS320C54xx (one of Texas Instruments' DSPs) is 16-bit long, which is also the smallest size of its general-purpose registers. And the TI C compiler defines char=short=int=16 bits on it.Luxurious
No, most RISC machines have 32-bit words, but can address single bytes. On MIPS for example, word definitely means 32 bits, but there's an lb (load byte) instruction which loads 8 bits.Rechaba
B
-2

The terms of BYTE and WORD are relative to the size of the processor that is being referred to. The most common processors are/were 8 bit, 16 bit, 32 bit or 64 bit. These are the WORD lengths of the processor. Actually half of a WORD is a BYTE, whatever the numerical length is. Ready for this, half of a BYTE is a NIBBLE.

Bulimia answered 9/2, 2018 at 17:59 Comment(1)
No, in CPUs with 32-bit words and 8-bit bytes (e.g. MIPS or ARM), half a word is 2 bytes.Rechaba
I
-4

In fact, in common usage, word has become synonymous with 16 bits, much like byte has with 8 bits. Can get a little confusing since the "word size" on a 32-bit CPU is 32-bits, but when talking about a word of data, one would mean 16-bits. Microcontrollers with a 32-bit word size have taken to calling their instructions "longs" (supposedly to try and avoid the word/doubleword confusion).

Indomitability answered 13/10, 2011 at 12:52 Comment(3)
That's entirely dependent on the CPU type. As you point out, on 32-bit non-IA32 machines, a "word" is typically 32 bites.Telephonic
@RossPatterson That's entirely dependent on whether you're developing software or eating dinner.Capote
ARM / MIPS / other mainstream RISC architectures have 32-bit words. It's the register width (on the 32-bit version of those ISAs) and the instruction width. 16 bits is a half-word, thus ARM instructions like ldrh to load 16 bits and zero-extend it into a 32-bit register. Or ldrsh to load and sign-extend 16 bits.Rechaba

© 2022 - 2024 — McMap. All rights reserved.