Solution:
Answer: 577
We prove that g(1)+g(2)+⋯+g(2n)=1+2n−2(n+1) for all n≥1, giving an answer of 1+26⋅9=577.
First note that g(2n)=1, and that we can view 0,1,…,2n−1 as n-digit binary sequences by appending leading zeros as necessary. (Then g(0)=0.)
Then for 0≤x≤2n−1, x and 2n−x are complementary n-digit binary sequences (of 0's and 1's), with x's strings of 1's (0's) corresponding to 2n−x's strings of 0's (resp. 1's). It follows that g(x)+g(2n−x) is simply 1 more than the number of digit changes in x (or 2n−x), i.e. the total number of 01 and 10 occurrences in x.
Finally, because exactly half of all n-digit binary sequences have 0,1 or 1,0 at positions k,k+1 (for 1≤k≤n−1 fixed), we conclude that the average value of g(x)+g(2n−x) is 1+2n−1=2n+1, and thus that the total value of g(x) is 21⋅2n⋅2n+1=(n+1)2n−2, as desired.