finding color of bits



hi
i am reading thru a book on digitizing text lines using c code.They
use a font data file containing unsigned char fonts [][16] with
elements like 0x00,0x7e,0x81 etc to represent each character .After a
text line is scanned 16 times the equivalent codes are stored in an
unsigned char[] bitImage.
Now the digitized line stored in bitImage is taken 1 character at a
time(ie 8 bits) and color of each is to be determined whether black or
white.
The book says that 'quickest method will be to write assembler code to
shift each octect(ie bitImage[i] in a for loop of i=0 to
i<bitImageSize) left 8 times so that carry flag will have color of
each bit'.The book says that no high level language can access the
carry flag and so a different method needs to be found.

I didn't quite understand that part.can someone clarify..?

The book continues to point out that 'bits in each octect can be got
by shifting it and ANDing with a constant'.Being new to bit
manipulation etc i couldn't quite write the code.if someone can help
pls do.

Finally the book comes up with a solution ,defining an unsigned char
c =0x80 and uses it as below

....
#define WHITE 0x00
#define BLACK 0xff
....
unsigned char octet ;
unsigned char *bit_image ;
....
currentcolor =WHITE

for (i=0 ; i<bitImageSize ; i++){
octet=bit_image[i] ;
...
for (c=0x80 ; c ; c>>=1){
if ((currentcolor&c)==(octet&c)) incrmntcurrentRunlength();
else startNewRunlength();
}
....
}

if somebody can explain what happens in this loop it would be a great
help..Being a beginner in c/bit manip etc i find it a little difficult
to understand these..

thanks in adv
harry
.



Relevant Pages

  • Re: Cohens paper on byte order
    ... > of type designated 'unsigned char' and not something ... a character variable is just that. ... is a wchar_t (also an integer type via typedef). ... conversely (except for padding and trap representations), ...
    (sci.crypt)
  • Re: A question regarding Q20.1 from c-faq.com
    ... return all possible character values and the out-of-band value EOF. ... values for unsigned char and int? ... conversion, I would consider it broken, but not necessarily ...
    (comp.lang.c)
  • Re: multi dimensional arrays as one dimension array
    ... An array m is guaranteed to have contiguous unsigned char objects, ... treat arbitrary bytes as character objects is ...
    (comp.lang.c)
  • Re: passing array to isdigit()
    ... > Peter Nilsson suggests processing a string by converting its ... Ordinary character strings should really be stored as unsigned char, ... yield the original character coding. ...
    (comp.lang.c)
  • Re: Whats the deal with the "toupper" family?
    ... irrational given that a character literal is of type "int" in C. ... The "toupper" function imposes a further constrait in that the value passed to it must be representable as a unsigned char. ... (If C does not require all character values to be positive, then again, this constrait too escapes me... ... return a non-negative int to represent an actual character code ...
    (comp.lang.c)