duminică, 22 iulie 2012
sâmbătă, 14 iulie 2012
nibble - Preluare de pe Vikipedia
Table of nibbles
The sixteen nibbles and their equivalents in other numeral systems:
0hex | = | 0dec | = | 0oct | 0 | 0 | 0 | 0 | |||
1hex | = | 1dec | = | 1oct | 0 | 0 | 0 | 1 | |||
2hex | = | 2dec | = | 2oct | 0 | 0 | 1 | 0 | |||
3hex | = | 3dec | = | 3oct | 0 | 0 | 1 | 1 | |||
4hex | = | 4dec | = | 4oct | 0 | 1 | 0 | 0 | |||
5hex | = | 5dec | = | 5oct | 0 | 1 | 0 | 1 | |||
6hex | = | 6dec | = | 6oct | 0 | 1 | 1 | 0 | |||
7hex | = | 7dec | = | 7oct | 0 | 1 | 1 | 1 | |||
8hex | = | 8dec | = | 10oct | 1 | 0 | 0 | 0 | |||
9hex | = | 9dec | = | 11oct | 1 | 0 | 0 | 1 | |||
Ahex | = | 10dec | = | 12oct | 1 | 0 | 1 | 0 | |||
Bhex | = | 11dec | = | 13oct | 1 | 0 | 1 | 1 | |||
Chex | = | 12dec | = | 14oct | 1 | 1 | 0 | 0 | |||
Dhex | = | 13dec | = | 15oct | 1 | 1 | 0 | 1 | |||
Ehex | = | 14dec | = | 16oct | 1 | 1 | 1 | 0 | |||
Fhex | = | 15dec | = | 17oct | 1 | 1 | 1 | 1 | |||
[edit]Examples
0100 0010 = 42 |
---|
0010 0000 1001 = 209 |
0001 0100 1001 = 149 |
0011 1001 0110 = 396 |
0001 0000 0001 = 101 |
0011 0101 0100 = 354 |
0001 0110 0100 = 164 |
[edit]Extracting a nibble from a byte
#define HI_NIBBLE(b) (((b) >> 4) & 0x0F) #define LO_NIBBLE(b) ((b) & 0x0F)
where
b
must be a variable or constant of an integer data type. (Of course, if b is more than a byte wide, only one of the bytes will be considered).
For example,
HI_NIBBLE(0xAB)==0xA
and LO_NIBBLE(0xAB)==0xB
.
In Common Lisp:
(defun hi-nibble (b) (ldb (byte 4 4) b)) (defun lo-nibble (b) (ldb (byte 4 0) b))
Abonați-vă la:
Postări (Atom)