A=(1,1,1,0,0,0,0,0)

b=(0,0,1,1,1,0,0,0)

c=(0,0,0,0,1,1,1,0)

d=(1,0,0,0,0,0,1,1)

where a,b,c,d are the bits of the number . D-most significant bit A-least significant bit

For x = 1 , counts up and for x = 0 it counts down. If smh can help me, it would make my day. Anyway,thanks in advance. Happy new Year.