Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

55 строки
1.3 KiB
C++

#include <iostream>
#include <cassert>
using namespace std;
//char nibble_to_hex(uint8_t i)
char nibble_to_hex(uint8_t i) //Conversion to hex format
{
assert(0x0 <= i && i <= 0xf);
//return "0123456789abcdef"[i];
if (i < 10)
{
return i + '0';
}
else
{
return 'a' + (i - 10);
}
}
uint8_t jun_nibble(uint8_t i) //Extracting the junior Nibble
{
return i & 0x0f;
}
int main()
{
assert(nibble_to_hex(0x0) == '0');
assert(nibble_to_hex(0x1) == '1');
assert(nibble_to_hex(0x2) == '2');
assert(nibble_to_hex(0x3) == '3');
assert(nibble_to_hex(0x4) == '4');
assert(nibble_to_hex(0x5) == '5');
assert(nibble_to_hex(0x6) == '6');
assert(nibble_to_hex(0x7) == '7');
assert(nibble_to_hex(0x8) == '8');
assert(nibble_to_hex(0x9) == '9');
assert(nibble_to_hex(0xa) == 'a');
assert(nibble_to_hex(0xb) == 'b');
assert(nibble_to_hex(0xc) == 'c');
assert(nibble_to_hex(0xd) == 'd');
assert(nibble_to_hex(0xe) == 'e');
assert(nibble_to_hex(0xf) == 'f');
cout << nibble_to_hex(10) << endl;
//cout << hex << static_cast(jun_nibble(0xce)) << endl;
cout << "Junior nibble: " << hex << +jun_nibble(0xce) << endl; //junior nibble
cout << "Press any key for exit... ";
cin.get();
return 0;
}