Contents
Terminology
Term 
Bits 
Bytes 
NASM 
GAS 
bit 
1 bit 



trit ^{1} 
bits 



nibble 
4 bits 
½ byte 


byte 
8 bits 
1 byte 
DB 
.byte 
word 
16 bits 
2 byte 
DW 
.word 
dword or double word 
32 bits 
4 bytes 
DD 
.long 
qword or quad word 
64 bits 
8 bytes 
DQ 

tword or ten word 
80 bits 
10 bytes 
DT 

oword or octo word 
128 bits 
16 bytes 
DO 

yword ^{2} 
256 bits 
32 bytes 
DY 

zword ^{3} 
512 bits 
64 bytes 
DZ 

 Used in ternary arithmetic, beyond scope.
 Intel AVX
YMM
register.
 Intel AVX512
ZZM
register.
Binary
Binary numbers, or bits are numbers in the base2 number system. “Orinary”
numbers are in base10, hexadecimal numbers are in base16:
Nibbles
A byte consists of two nibbles, or half bytes. A nibble contains 4 bits of
information, thus an 8 bit byte contains two nibbles.
Bit operations
Bit masks
Counting bits
Published in 1988, the C Programming Language 2nd Ed. by Brian W. Kernighan and Dennis M. Ritchie.
Counting bits in 14, 24 or 32bit words using 64bit instructions
Swapping values with XOR
You can do triple XOR
to swap two values without using a temporary register:
Reverse bits in a byte
Reverse bits in a byte using 64bit multiply and modulus
By Sean Anderson, July 13, 2001.
Multi byte packing
Bit matrix multiplication
Given matrices and :
We can calculate as:
And for vector :
We can calculate as:
Working with bytes in programming languages
Language 
Example 
Note 
C 
uint8_t b = 0x2a; b = c; 
Masking may be required 
Java 
static byte b = 0x2a; b = c; 
Guaranteed to be 8 bit byte 
PHP 
$b = 0x2a; $b = ($b  $c) & 0xff; 
No byte type, masking required (depends on size of c ) 
Python 
b = bytearray(1); b[0] = 0x2a; b[0] = c[0]; 
Guaranteed to be 8 bit byte 
Ruby 
b = 0x2a; b = (b  c) & 0xff 
No byte type, masking required (depends on size of c ) 
Leave your Message here...