[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RE: 4-bit type



Greetings,
	You might try something like this...

#include<stdio.h>
#include<stdlib.h>

void main(void)
{
	FILE *fpin;
	char cread;
	char chi;
	char clo;

	if( (fpin = fopen("FILENAME","r")) == NULL){
		printf("Cannot Open File\n");
		exit(1);
	}

	while( (cread = fgetc(fpin)) != EOF){
		clo = cread & 15;
		chi = cread & 240;

		/* Do your thing here */
	}

	flclose(fpin);
}

	You could read the 4-bit values into an array, or use them two at a time.

Brooks

	P.S. No, I didn't test this code, and I am not 100% sure about the bit
twiddling.


> -----Original Message-----
> From: Patrick Dahiroc [mailto:patd@dahiroc.net]
> Sent: Friday, November 10, 2000 7:32 AM
> To: debian-user@lists.debian.org
> Subject: 4-bit type
>
>
> here's my problem:  i need to read a binary file 4-bits at time.
>
> is it possible to create a new type that is 4-bits wide?  if so how do
> i go about it
>
> thanks
> pd
>
> --
>
>
> "As a general rule, if you have trouble
>  with the binary system, then probably it
>  is because you do not really understand
>  the decimal system ..."
>  		R.W. Hamming
>
>
> --
> Unsubscribe?  mail -s unsubscribe
> debian-user-request@lists.debian.org < /dev/null
>
>



Reply to: