Bit manipulation

usually every number is represented by 32 bits number in memory what the exact concepts .
Like it will have 2 is represent by 0000010 like that

range of long int : -2,147,483,647 to 2,147,483,647
CONCEPT: 32-bit [CPU] and [ALU] architectures are those that are based on [registers] [address buses], or [data buses] of that size. 32-bit [microcomputers] are computers in which 32-bit [microprocessors] are the norm.

@chhavibansal okay its all depends upon the architectures of the CPU. so when we are executing problems on the 64 bit computer CPU so we have to imagize of the 64 bit number for each integer

true
u got the logic.

@chhavibansal thanks
while solving today leet code problem for complement number I am n’t able to pass one test case which is the largest +ve number and going through the some solution some i found out the last number is converted into unsigned number i didn’t get this .

B
int number_complement(int num) {
int nb =(unsigned) floor(log2(num)+1)
int mask = (1 << num)-1;
return num ^ mask;
}

I didn’t get this for largest +ve number? Can u help me out the understand this concepts

signed bit is of 32 bits as we discussed earlier, but hte 32nd bit is used to signify is the number is +ve or -ve
hence atmost 2^31 bits tell the value of the number

hence in order to solve the no we need unsigned bit which has all +ve numbers ie the last bit is not used to tell +ve or -ve number

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

@chhavibansal I got ur point ur are great explainer?
One concern from ur end.
If I am trying to cover a topic and move to the next topics it seems like I forget the previous one and then I have to revise all the topics.
Are any better approaches while learning algorithms ?

Thanks for the complement. I suppose that’s not ‘?’
Yes it’s always a problem when u are new to DSA that you happen to forget topics, but it’s like a gradual process you got to revise them on and off
Like I even made 3 leetcode sessions doing the same question over and over again
It’s fine give time to the important topics, try to understand why things are happening.
Why’s will help u go a longer way and remember them for a longer time

@chhavibansal got ur point i will trying to follow this ways. thanks for the suggesstions

1 Like