Created
March 28, 2012 22:24
-
-
Save kg4sgp/2231082 to your computer and use it in GitHub Desktop.
displays binary... useing in another program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
char testbit[] = {0x7e,0xff}; | |
unsigned char teststring[] = "THIS IS SO COOL"; | |
void leftShift(unsigned char*, long unsigned int); | |
void displayBits(char*, int); | |
void leftShift(unsigned char *array, long unsigned int length){ //this function works | |
array[0] = (array[0]) << 1; | |
if(length == sizeof(unsigned char)){ | |
return; | |
} | |
int i; | |
unsigned char tmpbit; | |
for(i = 0; i < (length-1); i++){ | |
tmpbit = (array[i+1] & 0x80); | |
tmpbit >>= 7; | |
array[i] |= tmpbit; | |
array[i+1] = (array[i+1]) << 1; | |
} | |
array[length] = array[length] << 1; | |
} | |
void displayBits(char* whatever,int length){ // this one stops after 8bytes | |
printf("\n\n%d\n\n", length); | |
int i; | |
for(i = 0; i < length; i++){ | |
printf("%d", ((whatever[0] >> 7)&1)); | |
leftShift(&whatever[0], sizeof(whatever)); | |
} | |
} | |
int main(char argc[], char *argv[]){ | |
displayBits(&teststring[0], sizeof(teststring)*8); | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment