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=0oct0000
1hex=1dec=1oct0001
2hex=2dec=2oct0010
3hex=3dec=3oct0011
4hex=4dec=4oct0100
5hex=5dec=5oct0101
6hex=6dec=6oct0110
7hex=7dec=7oct0111
8hex=8dec=10oct1000
9hex=9dec=11oct1001
Ahex=10dec=12oct1010
Bhex=11dec=13oct1011
Chex=12dec=14oct1100
Dhex=13dec=15oct1101
Ehex=14dec=16oct1110
Fhex=15dec=17oct1111

[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.
(defun hi-nibble (b)
  (ldb (byte 4 4) b))
(defun lo-nibble (b)
  (ldb (byte 4 0) b))

Niciun comentariu: