1290 ) Converting a binary linked list to an integer

Converting a binary number to linkedlist
in this problem the code looks like this:
in the bit manipulation we declare res=0
in the loop we first shift res by 1 towards the left why? first we must add the current value then shift by one right?

int res=0;
while(head){
 res=res<<1; //why do we increment here
 res=res| head->value;
 head=head->next;
 //and not here res=res<<1
 }
 

problem link
https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/

Comments (1)