i've dynamically allocated an array of two bytes and begun playing around with the bits.
what i've wanted to do is have the program count how many 1s and 0s are in the memory allocated and print out the bits in the bytes. ive gotten it done so far with this:

Code:
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"



int main(int g, _TCHAR* argv[])
{
	int bitCount1 = 0;
	int bitCount0 = 0;
	char *ptr;
	ptr = (char*)malloc(2);
	
for(int i=0; i < 2; ++i) {
	for(int j=0; j < 8; ++j) {
/* lowest bit is set, add to number of set bits */
		if ((*ptr & 1) != 0)
		{printf("%d", 1);
		++bitCount1;}
		else {(++bitCount0);
		printf("%d", 0);}
/* reduce value at ptr by power of 2 */
*ptr >>= 1;
}
/* go to next byte addressed by ptr */
++ptr;
}

printf("\nThe number of ones in the memory allocated: %d\n", bitCount1);
printf("The number of zeros in the memory allocated: %d\n", bitCount0);

getchar();
}
the output right now is:

1011001110110011
The number of ones in the memory allocated: 10
The number of zeros in the memory allocated: 6

the only thing that bothers me is that both bytes have the same exact bit pattern of 10110011. the next thing i wanted to do was to find the hamming distance but it is clearly 0 in this situation.

am i doing everything right here? is there a reason both bytes have the same bit pattern, i was expecting them to have completely different bit patterns since they are supposed to be different bytes. any help here?