Thread: Convert 0 and 1 stream data to solid white and solid black character (like barcode)

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Convert 0 and 1 stream data to solid white and solid black character (like barcode)

    How to convert 0 and 1 stream data to solid white and solid black character (like barcode).
    I want to make barcode from 0 and 1 stream.
    example: 1110011001110 is black black black white white black black white white black black black white
    (black and white in the example mean solid black character and solid white character )
    If you know how to do that please tell me and if you can show the example source to do that please show me . Thank you for your information.

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    this depends, console mode(cheap DOS imitation)? OS? compiler?
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    heres a simple example to try to get you going, it accepts a long value in decimal and analysis every bit and prints its binary equivelant (in reverse), so if you use this you'll have to reverse the output before printing or reverse the inputted numbers, so if you were to reverse the barcodes you would do:
    213 = 11010101
    10101011 = 171
    there for if you were to pass through the value 171 you would get the top barcode.

    Code:
    // Prints the binary number out
    void printcode(long barcodenum)
    {
    	int bitpos=1;
    	long counter;
    
    	printf("BARCODE: ");
    // 1073741824 is max value of a long with one binary value, if you were doing an int, you would put: 16384
    // because 16384 = 100000000000000
    	for(counter=1;counter<=1073741824 && counter>0;counter*=2)
    	{
    		if((barcodenum & counter)>0)
    			printf("1");
    		else
    			printf("0");
    		bitpos++;
    	}
    }
    
    int main()
    {
    	printcode(171);
    	return 0;
    }

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You may want to modify your loop accordingly, and use bit shifting:
    Code:
    for( x=0; x<(sizeof(int)*8); x++ )
    {
        fprintf( stdprn, "%c", barcode & (1<<x) ? 217 : ' ' );
    }
    Assuming of course that you've actually opened the printer for writing... Anyway, in a console that should give you a solid block for a match, and a white space for a non-match.

    Assuming of course that you can actually access a printer that is hooked to your printer port in console mode.

    Of course, you could have just listened to my answer the first time I replied to your original post, and you wouldn't have had to ask again.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed