[Courses] Re: [C] My Life program...
Suzi Anvin
suzi at anvin.org
Sat Aug 3 18:44:04 EST 2002
Sorry to take a while getting back to you, I've been out of town for the
past week and a half...
Cynthia Grossen wrote:
> array[bit/8] &= ~(1<<(bit%8));
>
> This line strikes me as really intense. It seems like there's so much going
> on here.
> My interpretation of the line is:
> Do a bitwise AND on the array at position bit/8 with the bitwise complement
> of 1 left-shifted bit%8 positions.
> Is this a correct interpretation?
Okay, this was the newer part of C to me and I can only think it through
in my own words at the moment, so... (hey, review for me as well!)
This is, unless my brain is totally fried from driving south too long
int he hot sun, from the clearbit function? It makes the most sense to
me backwards... (1<<(bit%8)) takes a 1 and moves it into the position
of the bit in question, creating what my brain thinks of as the
comparison byte. the ~ reverses everything so the comparison byte has a
0 at the bit in question and all 1's everywhere else. Then array[bit/8]
&= compares all the bits in the byte and leaves behind a 1 wherever both
bytes have a 1. So any 1's in the original byte stay, except for the
bit indicated by the bit number, which will either remain a 0 or be
turned into a 0.
>
> printf("Error: You must give all 62 characters. Only x's and .'s please."
> "\x1b[1A\x1b[1G");
> Also on this line, the arguments given for printf "\x1b[1A\x1b[1G" what do
> they mean?
> printf("\x1b[H\x1b[2J");
Those codes would work only in a unix terminal window. They're standard
console codes, which I learned about from the manual by typing : man 4
console_codes. One of the console codes I wanted to use didn't work
with kconsole (F - move cursor up X rows to collumn 1) The codes above,
on a unix console only, do the following:
\x1b[ The escape character: tells the console to expect a command
1A Moves the cursor up 1 row
1G Moves the cursor to collumn 1 in the current row
H Moves currsor to the indicated row and coolumn, default is the
top left
2J erase whole display
I would expect that my program would NOT WORK on non-unix systems,
sorry, should have mentioned that somewhere...
-Suzi
More information about the Courses
mailing list