Bitwise Operators C/C++ : Find the n-th bit #OR #AND #shorts

preview_player
Показать описание
Hello everyone , I think that we have already made a video about this, but I want to explain it really fast this time and use my voice for once . Numbers are defined by arrays of 1s and 0s , 100001 and then converted to anything you need, 0x0011 is just 3 in Base2. We can cut the numbers to the digit we want to find and compare that Spot with 1. If the return is a one , we know that there is a one on that spot. And this is all you need to know .
Рекомендации по теме
Комментарии
Автор

Hi;
You going farther and more to get any data type the nth bit ;
Template<type name T, int N = 8*sizeof(T)>
Int get_nth_bit(T x, int n)
{
Check n that should be 0<n<N;
Unsigned char * p = (unsigned char*) &x;

Int bit = (*(p+n/8)& (1<<n%8))>>n%8;
Return bit;
}

__hannibaal__
join shbcf.ru