Hi all,
I want to read the pixel values of a .bmp image(which will be input to
the code) into a matrix...plz help me out as i can not understand how
to achieve this...
thanks in advance
biplab
|
|
0
|
|
|
|
Reply
|
getbiplab (15)
|
9/10/2008 12:57:49 PM |
|
biplab said:
> Hi all,
> I want to read the pixel values of a .bmp image(which will be input to
> the code) into a matrix...plz help me out as i can not understand how
> to achieve this...
What have you tried so far?
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
|
|
0
|
|
|
|
Reply
|
rjh (10789)
|
9/10/2008 1:12:21 PM
|
|
On Sep 10, 6:12=A0pm, Richard Heathfield <r...@see.sig.invalid> wrote:
> biplab said:
>
> > Hi all,
> > I want to read the pixel values of a .bmp image(which will be input to
> > the code) into a matrix...plz help me out as i can not understand how
> > to achieve this...
>
> What have you tried so far?
>
> --
> Richard Heathfield <http://www.cpax.org.uk>
> Email: -http://www. +rjh@
> Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
> "Usenet is a strange place" - dmr 29 July 1999
I have read the file using fopen...and then read the value...bt
nothing is read...I have a code in C which access the vedio memory to
print an image....can you please help me out from that code how can i
read the pixel vales and have the same image as output as the input...
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <mem.h>
#include <string.h>
#include <conio.h>
#include <fcntl.h>
#include <io.h>
#include <math.h>
unsigned char r[360],mini,mode;
unsigned char rgb[256][3];
char *fullname;
char *fname;
unsigned int screen_width=3D320;
unsigned int first_row=3D0,first_column=3D0,last_row=3D0,last_column=3D0;
int handle,i,j,rem,color_bits;
long int
file_size,data_offset,size_info_header,width,height,compression,
image_size,xpelspermeter,ypelspermeter,colorsused,colorsimpt;
float theta;
void drawdot(int y, int x, int pal_index){
_AX=3Dpal_index;
_CX=3Dx;
_DX=3Dy;
_AH=3D0x0c;
_BH=3D0x00;
geninterrupt(0x10);
}
void main(){
gets(fname);
strcpy(fullname,fname);
strcat(fullname,".bmp");
handle=3D_open(fullname,O_RDONLY);
if (handle=3D=3D-1) exit(EXIT_FAILURE);
_read(handle,r,2);
if (r[0] !=3D'B' | r[1] !=3D'M') exit(EXIT_FAILURE);
_read(handle,r,
4);file_size=3Dr[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,2);
_read(handle,r,2);
_read(handle,r,4);
data_offset=3Dr[0]+256*r[1]+65536*r[2]+0x1000000*r[3];
_read(handle,r,4);
size_info_header=3Dr[0]+256*r[1]+65536*r[2]+0x1000000*r[3];
if (size_info_header !=3D40) exit(EXIT_FAILURE);
_read(handle,r,4);
width=3Dr[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
if (width > screen_width) exit(0);
_read(handle,r,4);
height=3Dr[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,2);
if (r[0] !=3D 1) exit(EXIT_FAILURE);
_read(handle,r,2);
color_bits=3Dr[0];
_read(handle,r,4);
compression=3Dr[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
image_size=3Dr[0]+256*r[1]+256*256*r[2]+256*256*256*r[3];
_read(handle,r,4);
xpelspermeter=3Dr[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
ypelspermeter=3Dr[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
colorsused=3Dr[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
colorsimpt=3Dr[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_AX=3D0x1201;_BL=3D0x33;geninterrupt(0x10);//don't add RGB
_AX=3D0x0013;geninterrupt(0x10);//set mode 13 i.e. 320x200x256
for (i=3D0;i<256;i++) {
_read(handle,r,4);
rgb[i][0]=3Dr[2];rgb[i][1]=3Dr[1];rgb[i][2]=3Dr[0];
}
_ES=3DFP_SEG(rgb);_DX=3DFP_OFF(rgb);
_BX=3D0;_CX=3D0x100; _AX=3D0x1012;
geninterrupt(0x10);//set DAC from rgb
first_column=3D(screen_width-width)/2;
last_row=3Dfirst_row+height-1;
last_column=3Dfirst_column+width-1;
rem=3D4 - (width % 4);
for (i=3D0;i<=3Dheight-1;i++) {
_read(handle,r,width);
for (j=3D0;j<=3Dwidth-1;j++) drawdot(first_column+j,last_row-i,r[j]);
if (rem=3D=3D1) _read(handle,r,1);
else if (rem=3D=3D2) _read(handle,r,2);
else if (rem=3D=3D3) _read(handle,r,3);//getch();
}
_close(handle);
getch();
_AX=3D0x1201;_BL=3D0x33;geninterrupt(0x10);//don't add RGB
_AX=3D0x0003;geninterrupt(0x10);//set mode 3 i.e. 16-color text
}
1st of all i will be highly obliged if you let me know what the code
is doing and how??/As i have found the code in the internet and am a
newbie in C...
thanks in advance...
biplab
|
|
0
|
|
|
|
Reply
|
getbiplab (15)
|
9/10/2008 1:21:59 PM
|
|
biplab wrote:
> On Sep 10, 6:12 pm, Richard Heathfield <r...@see.sig.invalid> wrote:
>> biplab said:
> I have read the file using fopen...and then read the value...bt
> nothing is read...I have a code in C which access the vedio memory to
> print an image....can you please help me out from that code how can i
> read the pixel vales and have the same image as output as the input...
> unsigned char r[360],mini,mode;
<snip bad code>
> }
>
> 1st of all i will be highly obliged if you let me know what the code
> is doing and how??/As i have found the code in the internet and am a
> newbie in C...
> thanks in advance...
> biplab
It seems to read a bmp file, very badly (and assumes it is 8-bit colour
indexed), then displays it in a highly machine-specific manner, which
probably won't work on a modern machine.
I suggest you find some more up-to-date code on the internet. And separate
out the bmp loading from the display. You might try google on "bmp file
format".
--
Bartc
|
|
0
|
|
|
|
Reply
|
bc (2211)
|
9/10/2008 4:43:25 PM
|
|
On Sep 10, 8:21=A0am, biplab <getbiplab@gmail.com> wrote:
<snip>
> 1st of all i will be highly obliged if you let me know what the code
> is doing and how??/As i have found the code in the internet and am a
> newbie in C...
> thanks in advance...
The code doesn't do much. It invokes undefined behavior
- at line 1 in main() (calling gets() with an uninitialized pointer)
- at line 2 in main() (calling strcpy() with an uninitialized
pointer)
- at line 3 in main() (calling strcat() with an uninitialized
pointer)
- at line 4 in main() (calling _open() with an uninitialized
pointer)
....and presumably a few dozen other times. The first three are the
same kind of UB: writing to unexistent/unowned memory. This is likely
going to crash the program.
Sebastian
|
|
0
|
|
|
|
Reply
|
s0suk3 (372)
|
9/10/2008 6:47:21 PM
|
|
"biplab" <getbiplab@gmail.com> wrote in message news
>I have read the file using fopen...and then read the value...bt
>nothing is read...I have a code in C which access the vedio memory to
>print an image....can you please help me out from that code how can i
>read the pixel vales and have the same image as output as the input...
>
Don't revinvent the wheel. There's a portable BMP loader on my website that
you are welcome to take. Essentially it does what you were doing, examining
the binary file byte by byte to decode it, but all the special cases are
coded in and tested.
You need to know whether your display system is a modern one that handles
truecolor images, or an old-fashioned one that uses color-index mode.
If the former, you wnat to call loadbmp() to retrieve rgb values. If the
latter, loadbmp8bit() to get the colour index values and the palette.
Then look in the Microsoft documentation to determine how to create a
skeleton windows application. You can then creagte a window of the desired
size and write the image to it, pixel by pixel. Once you get this working
you can try the faster block bit transfer, if performance is a problem.
The assembly interrupts probably won't work any more.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
|
|
0
|
|
|
|
Reply
|
regniztar (3128)
|
9/10/2008 8:21:18 PM
|
|
On Sep 10, 9:47 pm, s0s...@gmail.com wrote:
> On Sep 10, 8:21 am, biplab <getbip...@gmail.com> wrote:
>
> <snip>
>
> > 1st of all i will be highly obliged if you let me know what the code
> > is doing and how??/As i have found the code in the internet and am a
> > newbie in C...
> > thanks in advance...
>
> The code doesn't do much. It invokes undefined behavior
>
> - at line 1 in main() (calling gets() with an uninitialized pointer)
Well, not really.
That code would fail to translate, because of the non-standard
headers. If not, how can you guess the contents of the non-standard
headers?
For example, <dos.h> might had:
#undef gets
#define gets(x) (void)0
<snip>
|
|
0
|
|
|
|
Reply
|
vippstar (1211)
|
9/10/2008 8:29:11 PM
|
|
"Malcolm McLean" <regniztar@btinternet.com> wrote in message
news:vcydnYbhTtiwsVXVnZ2dnUVZ8uadnZ2d@bt.com...
> Don't revinvent the wheel. There's a portable BMP loader on my website
> that you are welcome to take. Essentially it does what you were doing,
> examining the binary file byte by byte to decode it, but all the special
> cases are coded in and tested.
>
> You need to know whether your display system is a modern one that handles
> truecolor images, or an old-fashioned one that uses color-index mode.
> If the former, you wnat to call loadbmp() to retrieve rgb values. If the
> latter, loadbmp8bit() to get the colour index values and the palette.
[snip]
Malcom can you mention these values. I might be interested in taking a swing
at this myself. You mention byte by byte. Since a char is a byte would you
recommend using getc and putc or fread ? I would be interested in the
symantics of your code.
Bill
|
|
0
|
|
|
|
Reply
|
nospam268 (588)
|
9/10/2008 10:50:29 PM
|
|
On Wed, 10 Sep 2008 06:21:59 -0700 (PDT), biplab <getbiplab@gmail.com>
wrote:
>I have read the file using fopen...and then read the value...bt
>nothing is read...I have a code in C which access the vedio memory to
>print an image....can you please help me out from that code how can i
>read the pixel vales and have the same image as output as the input...
>
snip some really bad code
>1st of all i will be highly obliged if you let me know what the code
>is doing and how??/As i have found the code in the internet and am a
>newbie in C...
Make a note of whatever site you found that code on and NEVER visit it
again. The code is absolutely hopeless, much worse than merely
obsolete. You need to start again from scratch.
Use only standard headers and functions so the people here can
help you. If you must use system specific features, ask in a
newsgroup that discusses that system.
The use of that many global variables is a 99% indicator of a
sloppy design.
Look in your reference for the correct signature of main().
You are attempting to read binary data. Open the file for that
mode and use an input function that supports it, such as fread.
Make sure every pointer you use points somewhere before you use
it.
Use horizontal white space to make your code readable.
--
Remove del for email
|
|
0
|
|
|
|
Reply
|
schwarzb3978 (1358)
|
9/11/2008 12:11:16 AM
|
|
On Wed, 10 Sep 2008 05:57:49 -0700 (PDT), biplab posted:
> Hi all,
> I want to read the pixel values of a .bmp image(which will be input to
> the code) into a matrix...plz help me out as i can not understand how
> to achieve this...
>
> thanks in advance
>
> biplab
Standard C is the wrong tool for this. Change tools.
--
War will never cease until babies begin to come into the world with larger
cerebrums and smaller adrenal glands. 2
H. L. Mencken
|
|
0
|
|
|
|
Reply
|
ron7715 (217)
|
9/11/2008 1:35:43 AM
|
|
Ron Ford <r...@example.invalid> wrote:
> biplab posted:
> > I want to read the pixel values of a .bmp image(which
> > will be input to the code) into a matrix...plz help me
> > out as i can not understand how to achieve this...
>
> Standard C is the wrong tool for this.
Why do you say that?
--
Peter
|
|
0
|
|
|
|
Reply
|
airia (1802)
|
9/11/2008 2:44:06 AM
|
|
On Wed, 10 Sep 2008 19:44:06 -0700 (PDT), Peter Nilsson posted:
> Ron Ford <r...@example.invalid> wrote:
>> biplab posted:
>>> I want to read the pixel values of a .bmp image(which
>>> will be input to the code) into a matrix...plz help me
>>> out as i can not understand how to achieve this...
>>
>> Standard C is the wrong tool for this.
>
> Why do you say that?
Because extensions make this easy.
--
War will never cease until babies begin to come into the world with larger
cerebrums and smaller adrenal glands. 2
H. L. Mencken
|
|
0
|
|
|
|
Reply
|
ron7715 (217)
|
9/11/2008 6:44:10 AM
|
|
"Bill Cunningham" <nospam@nspam.com> wrote in message
> Malcom can you mention these values. I might be interested in taking a
> swing at this myself. You mention byte by byte. Since a char is a byte
> would you recommend using getc and putc or fread ? I would be interested
> in the symantics of your code.
>
Writing a bmp loader is a good exercise.
The image dimensions, for example, are stored in little-endian order. If we
say
fread(&width, 1, 2, fp);
then we are relying on the fact that width is 2 bytes long, and
little-endian.
However if we say
int width;
width = fgetc(fp);
width |= fgetc(fp) << 8;
Then we retrieve the right value of width, regardless of whether integers
are 2 bytes or 4 bytes, or big- or little- endian.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
|
|
0
|
|
|
|
Reply
|
regniztar (3128)
|
9/11/2008 7:44:56 AM
|
|
"Ron Ford" <ron@example.invalid> wrote in message
>
> Because extensions make this easy.
>
You're right. For instance BMP files can be jpeg-compressed. This happens
but rarely, but it is in the file format. You are much better off calling an
image-loading routine supplied by Microsoft.
Unless that is you are not on a Windows machine.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
|
|
0
|
|
|
|
Reply
|
regniztar (3128)
|
9/11/2008 7:47:39 AM
|
|
"Malcolm McLean" <regniztar@btinternet.com> wrote in message
news:5qOdnZY_YvX5UVXVnZ2dnUVZ8tjinZ2d@bt.com...
> However if we say
>
> int width;
>
> width = fgetc(fp);
> width |= fgetc(fp) << 8;
>
> Then we retrieve the right value of width, regardless of whether integers
> are 2 bytes or 4 bytes, or big- or little- endian.
Ok I have no real experience with the binary operators so I'm going to
say your pipe symbol | is XOR. << is the left shift operator for an 8 bit
value. I really don't know yet how to use this in real time but I recognize
the symbols.
Bill
|
|
0
|
|
|
|
Reply
|
nospam268 (588)
|
9/11/2008 8:46:04 PM
|
|
On Sep 11, 11:46 pm, "Bill Cunningham" <nos...@nspam.com> wrote:
> "Malcolm McLean" <regniz...@btinternet.com> wrote in message
>
> news:5qOdnZY_YvX5UVXVnZ2dnUVZ8tjinZ2d@bt.com...
>
> > However if we say
>
> > int width;
>
> > width = fgetc(fp);
> > width |= fgetc(fp) << 8;
>
> > Then we retrieve the right value of width, regardless of whether integers
> > are 2 bytes or 4 bytes, or big- or little- endian.
>
> Ok I have no real experience with the binary operators so I'm going to
> say your pipe symbol | is XOR.
lol.
|
|
0
|
|
|
|
Reply
|
vippstar (1211)
|
9/11/2008 8:52:51 PM
|
|
Bill Cunningham said:
<snip>
> Ok I have no real experience with the binary operators so I'm going
> to
> say your pipe symbol | is XOR.
That's the wrong way to learn. Instead of guessing, consult your C
reference, which makes the roles of bitwise operators perfectly clear.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
|
|
0
|
|
|
|
Reply
|
rjh (10789)
|
9/11/2008 8:58:11 PM
|
|
vippstar@gmail.com writes:
> On Sep 10, 9:47 pm, s0s...@gmail.com wrote:
>> On Sep 10, 8:21 am, biplab <getbip...@gmail.com> wrote:
>>
>> <snip>
>>
>> > 1st of all i will be highly obliged if you let me know what the code
>> > is doing and how??/As i have found the code in the internet and am a
>> > newbie in C...
>> > thanks in advance...
>>
>> The code doesn't do much. It invokes undefined behavior
>>
>> - at line 1 in main() (calling gets() with an uninitialized pointer)
>
> Well, not really.
Well, yes, really.
> That code would fail to translate, because of the non-standard
> headers.
It *might* fail to translate, depending on the implementation. Unless
there's a statement in the standard that I've missed that says
anything that includes a non-standard header must fail to translate.
(Hint: There isn't.)
> If not, how can you guess the contents of the non-standard
> headers?
> For example, <dos.h> might had:
>
> #undef gets
> #define gets(x) (void)0
You can't *know* the contents of non-standard headers, but you can
certainly *guess*. For example, I guess, with a fairly high level of
confidence, that a <dos.h> header in any implementation that provides
it *doesn't* have the above macro definition.
The fact that <dos.h> is non-standard, and therefore off-topic in this
newsgroup, doesn't mean that we can or should pretend that it doesn't
exist or that it's likely to contain some implausible content.
Writing non-portable code is one of the main purposes of C, after all.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|
|
0
|
|
|
|
Reply
|
kst-u (21469)
|
9/11/2008 9:29:31 PM
|
|
"Bill Cunningham" <nospam@nspam.com> writes:
> "Malcolm McLean" <regniztar@btinternet.com> wrote in message
> news:5qOdnZY_YvX5UVXVnZ2dnUVZ8tjinZ2d@bt.com...
>> However if we say
>>
>> int width;
>>
>> width = fgetc(fp);
>> width |= fgetc(fp) << 8;
>>
>> Then we retrieve the right value of width, regardless of whether integers
>> are 2 bytes or 4 bytes, or big- or little- endian.
>
> Ok I have no real experience with the binary operators so I'm going to
> say your pipe symbol | is XOR. << is the left shift operator for an 8 bit
> value. I really don't know yet how to use this in real time but I recognize
> the symbols.
They're better referred to as bitwise operators. The term "binary
operator" commonly refers to an operator that takes two operands.
Your lack of experience with bitwise operators is no excuse for
*guessing* what they mean. "|" is not XOR. Consult your copy of
K&R2 (you've said you have one) to learn what it is, and what the
actual XOR operator looks like.
(Yes, << is the left shift operator, but it's not specific to 8
bit values.)
Last month, I gave you some advice about
the use of standard library functions. See
<http://groups.google.com/group/comp.lang.c/msg/6da991ad26d30ed9>.
Everything I wrote there applies equally to predefined operators,
at least to any that you're not familiar with. (At least this
time you're not writing code based on your guesses.)
One more thing: you're using <nospam@nspam.com> as your return
address, obviously to avoid spam. nspam.com happens to be a
real domain. I'm sure its owner doesn't appreciate getting
all the spam that would have gone to you. Use something like
<nospam@nospam.invalid> (see RFC 2606).
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|
|
0
|
|
|
|
Reply
|
kst-u (21469)
|
9/11/2008 9:44:52 PM
|
|
On Sep 12, 12:29 am, Keith Thompson <ks...@mib.org> wrote:
> vipps...@gmail.com writes:
> > On Sep 10, 9:47 pm, s0s...@gmail.com wrote:
>
> >> The code doesn't do much. It invokes undefined behavior
> >> - at line 1 in main() (calling gets() with an uninitialized pointer)
>
> > Well, not really.
>
> Well, yes, really.
>
> > That code would fail to translate, because of the non-standard
> > headers.
>
> It *might* fail to translate, depending on the implementation. Unless
Reading further,
"if not [...]"
So I did not say that it _must_ fail. I examined each posibility.
(I accept that this may not have been obvious, but these were my
intentions)
> there's a statement in the standard that I've missed that says
> anything that includes a non-standard header must fail to translate.
> (Hint: There isn't.)
>
> > If not, how can you guess the contents of the non-standard
> > headers?
> > For example, <dos.h> might had:
>
> > #undef gets
> > #define gets(x) (void)0
>
> You can't *know* the contents of non-standard headers, but you can
> certainly *guess*. For example, I guess, with a fairly high level of
> confidence, that a <dos.h> header in any implementation that provides
> it *doesn't* have the above macro definition.
>
> The fact that <dos.h> is non-standard, and therefore off-topic in this
> newsgroup, doesn't mean that we can or should pretend that it doesn't
> exist or that it's likely to contain some implausible content.
> Writing non-portable code is one of the main purposes of C, after all.
I disagree. After all, nasal demons were given life here. :-)
(according to the jargon file, comp.std.c actually)
Being more serious here, of course that gets call invoked undefined
behavior. However, don't you agree my post had some truth hidden in
it? You can't assume what happends if you don't know what the headers
do.
Plus, who knows, there might be an implementation whose header (one of
the non-standard headers) does have such (or similar) macro
definition, to prevent people from using gets.
|
|
0
|
|
|
|
Reply
|
vippstar (1211)
|
9/11/2008 9:57:43 PM
|
|
"Bill Cunningham" <nospam@nspam.com> writes:
> "Malcolm McLean" <regniztar@btinternet.com> wrote in message
> news:5qOdnZY_YvX5UVXVnZ2dnUVZ8tjinZ2d@bt.com...
>
>> However if we say
>>
>> int width;
>>
>> width = fgetc(fp);
>> width |= fgetc(fp) << 8;
>>
>> Then we retrieve the right value of width, regardless of whether integers
>> are 2 bytes or 4 bytes, or big- or little- endian.
>
> Ok I have no real experience with the binary operators so I'm going to
> say your pipe symbol | is XOR. << is the left shift operator for an 8 bit
> value. I really don't know yet how to use this in real time but I recognize
> the symbols.
>
> Bill
Wonderful Bill! You're trolling knows no bounds!
Pipe symbol is XOR. Priceless.
|
|
0
|
|
|
|
Reply
|
rgrdev (1814)
|
9/11/2008 10:19:18 PM
|
|
In article <lnfxo62wxw.fsf@nuthaus.mib.org>,
Keith Thompson <kst-u@mib.org> wrote:
....
>Writing non-portable code is one of the main purposes of C, after all.
Whoa!! What happened here??? Who hacked into Keith's account?
Let's be honest about this: How can you say "One of the main purposes
of X is to do Y, but you can't discuss Y in the newsgroup dedicated to X?"
It is simply absurd.
|
|
0
|
|
|
|
Reply
|
gazelle3 (1598)
|
9/12/2008 1:01:39 AM
|
|
"Keith Thompson" <kst-u@mib.org> wrote in message
news:lnbpyu2w8b.fsf@nuthaus.mib.org...
> One more thing: you're using <nospam@nspam.com> as your return
> address, obviously to avoid spam. nspam.com happens to be a
> real domain. I'm sure its owner doesn't appreciate getting
> all the spam that would have gone to you. Use something like
> <nospam@nospam.invalid> (see RFC 2606).
Ok thanks for letting me know.
Bill
|
|
0
|
|
|
|
Reply
|
nospam268 (588)
|
9/12/2008 1:24:31 AM
|
|
"Richard" <rgrdev@gmail.com> wrote in message
news:gac5j3$osb$1@registered.motzarella.org...
> Wonderful Bill! You're trolling knows no bounds!
>
> Pipe symbol is XOR. Priceless.
It's a bitwise or, as opposed to ||. Not very funny. I've never used the
bitwise operators so I'm going to read up on them.
Bill
|
|
0
|
|
|
|
Reply
|
nospam268 (588)
|
9/12/2008 1:26:06 AM
|
|
I'm getting better Keith with the functions. But things like the bitwise
operators as a perfect example I have never used. Pointers are another thing
not completely understood. When to declare a pointer and use & for example.
In reading a prototype I would have to experiment.
Bill
|
|
0
|
|
|
|
Reply
|
nospam116 (1187)
|
9/12/2008 1:29:53 AM
|
|
"Bill Cunningham" <nospam@nspam.com> writes:
> "Richard" <rgrdev@gmail.com> wrote in message
> news:gac5j3$osb$1@registered.motzarella.org...
>
>> Wonderful Bill! You're trolling knows no bounds!
>>
>> Pipe symbol is XOR. Priceless.
>
> It's a bitwise or, as opposed to ||. Not very funny. I've never used the
> bitwise operators so I'm going to read up on them.
As opposed to what? Yo think || is XOR now?
Watch out Linux Torwalds! There's a new man in town. Seriously. Give it
up. You're too transparent. No one can be this clueless.
>
> Bill
>
>
--
|
|
0
|
|
|
|
Reply
|
rgrdev (1814)
|
9/12/2008 1:43:13 AM
|
|
Ok I guess now after looking at wikipedia that XOR is ^ and | is OR. I
have not really encountered a use yet for these operators.
Bill
|
|
0
|
|
|
|
Reply
|
nospam116 (1187)
|
9/12/2008 1:45:30 AM
|
|
"Bill Cunningham" <nospam@nspam.invalid> writes:
> Ok I guess now after looking at wikipedia that XOR is ^ and | is OR. I
> have not really encountered a use yet for these operators.
>
> Bill
You don't have a copy of K&R?
|
|
0
|
|
|
|
Reply
|
rgrdev (1814)
|
9/12/2008 1:54:48 AM
|
|
On Thu, 11 Sep 2008 21:29:53 -0400, "Bill Cunningham"
<nospam@nspam.invalid> wrote:
> I'm getting better Keith with the functions. But things like the bitwise
>operators as a perfect example I have never used. Pointers are another thing
>not completely understood. When to declare a pointer and use & for example.
>In reading a prototype I would have to experiment.
It doesn't matter whether you have ever used it or not. It is the
idiocy of guessing instead of researching that people are commenting
on.
--
Remove del for email
|
|
0
|
|
|
|
Reply
|
schwarzb3978 (1358)
|
9/12/2008 2:05:28 AM
|
|
"Bill Cunningham" <nospam@nspam.invalid> writes:
> Ok I guess now after looking at wikipedia that XOR is ^ and | is OR. I
> have not really encountered a use yet for these operators.
You've said you have a copy of K&R2. Why the ^|&~ would you consult
Wikipedia?
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|
|
0
|
|
|
|
Reply
|
kst-u (21469)
|
9/12/2008 5:26:40 AM
|
|
Bill Cunningham said:
> Ok I guess now after looking at wikipedia that XOR is ^ and | is OR.
Stop guessing. Start reading K&R2.
> I have not really encountered a use yet for these operators.
Then ignore them, or learn about them, at your leisure. But guessing is
just ludicrous.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
|
|
0
|
|
|
|
Reply
|
rjh (10789)
|
9/12/2008 6:11:15 AM
|
|
Bill Cunningham wrote:
> Ok I guess now after looking at wikipedia that XOR is ^ and | is OR. I
> have not really encountered a use yet for these operators.
I routinely avoid reading discussions that you start; I'm not certain
that you're the troll that some people think you are, but I find it
psychically painful to see lots of good advice aimed at your head which
just bounces off without ever penetrating. Over more than a decade a lot
of good-hearted and very competent people have put a lot of effort into
trying to teach you C. Those same people could have spent the same
amount of effort to turn dozens of ordinary students into expert C
programmers; but it seems to have been utterly wasted on you.
However, I don't have any way to tell my web browser to filter out
entire threads on the basis of the fact that you started the thread; so
occasionally I do end up reading someone else's responses to you.
You've been repeatedly told not to guess at the answers, but to figure
them out. You apologize each time, but continue doing it. You've been
repeatedly told that your copy of K&R is a much better place to look for
answers than virtually any other source you are in the habit of using,
but it seems as though you almost never use K&R. You apologize each
time, and keep doing it.
There's unfortunately nothing unusual about people failing to take good
advice; but I'm curious if, instead of an apology, you could give us any
actual reason you had for ignoring the advice, even if it is a bad reason.
|
|
0
|
|
|
|
Reply
|
jameskuyper (5156)
|
9/12/2008 11:48:31 AM
|
|
James Kuyper <jameskuyper@verizon.net> writes:
> Bill Cunningham wrote:
>> Ok I guess now after looking at wikipedia that XOR is ^ and | is
>> OR. I have not really encountered a use yet for these operators.
>
> I routinely avoid reading discussions that you start; I'm not certain
> that you're the troll that some people think you are, but I find it
> psychically painful to see lots of good advice aimed at your head
> which just bounces off without ever penetrating. Over more than a
> decade a lot of good-hearted and very competent people have put a lot
> of effort into trying to teach you C. Those same people could have
> spent the same amount of effort to turn dozens of ordinary students
> into expert C programmers; but it seems to have been utterly wasted on
> you.
>
> However, I don't have any way to tell my web browser to filter out
> entire threads on the basis of the fact that you started the thread;
> so occasionally I do end up reading someone else's responses to you.
>
> You've been repeatedly told not to guess at the answers, but to figure
> them out. You apologize each time, but continue doing it. You've been
> repeatedly told that your copy of K&R is a much better place to look
> for answers than virtually any other source you are in the habit of
> using, but it seems as though you almost never use K&R. You apologize
> each time, and keep doing it.
>
> There's unfortunately nothing unusual about people failing to take
> good advice; but I'm curious if, instead of an apology, you could give
> us any actual reason you had for ignoring the advice, even if it is a
> bad reason.
I suspect he's the alter-ego of one of the ruder "regs". They feel they
have amended for their hateful, egotistical ways by responding politely
and calmly to someone who is obviously either simple or a troll. I think
troll but he does it so well... As Robert Downey Jr says (in the role of
a black soldier following a skin pigment augmentation) - "You made the
mistake of going 'full retard'".
|
|
0
|
|
|
|
Reply
|
rgrdev (1814)
|
9/12/2008 12:26:53 PM
|
|
"Bill Cunningham" <nospam@nspam.com> wrote in message
> It's a bitwise or, as opposed to ||. Not very funny. I've never used
> the bitwise operators so I'm going to read up on them.
>
At first sight the bitwise operators may appear entirely useless. Who wants
to set a bit to one if an only if two bits in the inputs are set?
However you'll soon realise that they are in fact very useful.
For instance
if( x & 1) /* if x is an odd number */
x & = 0xFF00; /* clear the lower 8 bits of x, also any bits above 16 */
lightswitch ^= 1; /* a toggle. The lightswitch goes on if it is off and vice
versa */
x <<= 1; /* these two lines will collect a series of bits in
integer */
x |= newbit; /* x, for instance for a compression algorithm */
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
|
|
0
|
|
|
|
Reply
|
regniztar (3128)
|
9/12/2008 7:10:16 PM
|
|
"Malcolm McLean" <regniztar@btinternet.com> wrote in message
news:bJ-dnT94I_EeVVfVnZ2dneKdnZydnZ2d@bt.com...
> At first sight the bitwise operators may appear entirely useless. Who
> wants to set a bit to one if an only if two bits in the inputs are set?
>
> However you'll soon realise that they are in fact very useful.
>
> For instance
>
> if( x & 1) /* if x is an odd number */
>
> x & = 0xFF00; /* clear the lower 8 bits of x, also any bits above 16 */
>
> lightswitch ^= 1; /* a toggle. The lightswitch goes on if it is off and
> vice versa */
>
> x <<= 1; /* these two lines will collect a series of bits in
> integer */
> x |= newbit; /* x, for instance for a compression algorithm */
>
Is the x you are working with a char ?
Bill
|
|
0
|
|
|
|
Reply
|
nospam7905 (3)
|
9/12/2008 8:25:50 PM
|
|
"Bill Cunningham" <nospam@nspam.inv> wrote in message
> Malcolm
>> For instance
>>
>> if( x & 1) /* if x is an odd number */
>>
>> x & = 0xFF00; /* clear the lower 8 bits of x, also any bits above 16 */
>>
>> lightswitch ^= 1; /* a toggle. The lightswitch goes on if it is off and
>> vice versa */
>>
>> x <<= 1; /* these two lines will collect a series of bits in
>> integer */
>> x |= newbit; /* x, for instance for a compression algorithm */
>>
>
> Is the x you are working with a char ?
>
Could be an unsigned char. Or could be an int. Except for the second
example, where we have at least 16 bits, and chars are almost always 8 bits.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
|
|
0
|
|
|
|
Reply
|
regniztar (3128)
|
9/12/2008 9:08:00 PM
|
|
"Bill Cunningham" <nospam@nspam.inv> writes:
> "Malcolm McLean" <regniztar@btinternet.com> wrote in message
> news:bJ-dnT94I_EeVVfVnZ2dneKdnZydnZ2d@bt.com...
>> At first sight the bitwise operators may appear entirely useless. Who
>> wants to set a bit to one if an only if two bits in the inputs are set?
>>
>> However you'll soon realise that they are in fact very useful.
>>
>> For instance
>>
>> if( x & 1) /* if x is an odd number */
>>
>> x & = 0xFF00; /* clear the lower 8 bits of x, also any bits above 16 */
>>
>> lightswitch ^= 1; /* a toggle. The lightswitch goes on if it is off and
>> vice versa */
>>
>> x <<= 1; /* these two lines will collect a series of bits in
>> integer */
>> x |= newbit; /* x, for instance for a compression algorithm */
>>
>
> Is the x you are working with a char ?
Will either a yes or no answer to that question be of any use to you?
The bitwise operators work on integer (and yes, char is an integer
type). Most of the time they *should* be used on unsigned integers
(char may be either signed or unsigned).
I don't think you have enough understanding of the bitwise operators
for your question to be meaningful. K&R2 discusses these operators.
Come back when you've read it.
BTW, I see you're now using <nospam@nspam.inv> as your return address.
My advice was to use ".invalid", not ".inv". The relevant RFC
guarantees that there will never be a ".invalid" top-level domain; it
makes no such guarantee about ".inv". This is yet another case where
you change something without understanding what you're doing.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|
|
0
|
|
|
|
Reply
|
kst-u (21469)
|
9/12/2008 9:18:52 PM
|
|
"Keith Thompson" <kst-u@mib.org> wrote in message
news:ln4p4m0wa7.fsf@nuthaus.mib.org...
> "Bill Cunningham" <nospam@nspam.invalid> writes:
>> Ok I guess now after looking at wikipedia that XOR is ^ and | is OR.
>> I
>> have not really encountered a use yet for these operators.
>
> You've said you have a copy of K&R2. Why the ^|&~ would you consult
> Wikipedia?
I happened to be online, looked up wikipedia quickly and found my
answer. Otherwise I would have to leave the computer immediately dig through
some books and thought I'd leave that for later.
Kand R2 is very much a mouthful, or should I say head ful. I have
learned more at times from other texts and the help I get here and other
places. Nevertheless I do consult it from time to time.
Bill
|
|
0
|
|
|
|
Reply
|
nospam7905 (3)
|
9/12/2008 9:20:04 PM
|
|
"Barry Schwarz" <schwarzb@dqel.com> wrote in message
news:3uijc4p68seogfajctmi8en47r4ugfaetg@4ax.com...
> It doesn't matter whether you have ever used it or not. It is the
> idiocy of guessing instead of researching that people are commenting
> on.
What makes you think I am not researching things. I immediately went to
wikipedia to find out answers fast. I will read up on kandr2 when I decide
to use bitwise operators then if I am confused I will inquire here.
Bill
|
|
0
|
|
|
|
Reply
|
nospam116 (1187)
|
9/12/2008 9:33:04 PM
|
|
"Richard Heathfield" <rjh@see.sig.invalid> wrote in message
news:NJadnXUmpfN5m1fVnZ2dnUVZ8h6dnZ2d@bt.com...
> Then ignore them, or learn about them, at your leisure. But guessing is
> just ludicrous.
When I am ready to research them I will read kandr2 or something similar
if kandr2 is too much of a mouthful, and ask if confused accordingly. but I
immediately went to wikipedia to find answers fast while online.
Bill
|
|
0
|
|
|
|
Reply
|
nospam116 (1187)
|
9/12/2008 9:35:49 PM
|
|
In article <jGsyk.1084$jE1.658@trnddc03>, James Kuyper
<jameskuyper@verizon.net> wrote:
> Bill Cunningham wrote:
> > Ok I guess now after looking at wikipedia that XOR is ^ and | is OR. I
> > have not really encountered a use yet for these operators.
>
> I routinely avoid reading discussions that you start; I'm not certain
> that you're the troll that some people think you are, but I find it
> psychically painful to see lots of good advice aimed at your head which
> just bounces off without ever penetrating. Over more than a decade a lot
> of good-hearted and very competent people have put a lot of effort into
> trying to teach you C. Those same people could have spent the same
> amount of effort to turn dozens of ordinary students into expert C
> programmers; but it seems to have been utterly wasted on you.
I don't understand why anyone who's been here more than a week even reads
his posts. Whatever the reason, it's not worth time even reading, much
less answering, posts with his name on it. It's like optimizing a program:
don't waste time on the areas where your work won't make any difference.
Nothing personal, just that measurement has shown that effort spent
answering his posts is wasteful.
|
|
0
|
|
|
|
Reply
|
blargg.h4g (301)
|
9/14/2008 12:20:30 PM
|
|
"blargg" <blargg.h4g@gishpuppy.com> wrote in message
news:blargg.h4g-1409080720300001@192.168.1.4...
> In article <jGsyk.1084$jE1.658@trnddc03>, James Kuyper
> <jameskuyper@verizon.net> wrote:
>
>> Bill Cunningham wrote:
>> > Ok I guess now after looking at wikipedia that XOR is ^ and | is
>> > OR. I
>> > have not really encountered a use yet for these operators.
>>
>> I routinely avoid reading discussions that you start; I'm not certain
>> that you're the troll that some people think you are, but I find it
> I don't understand why anyone who's been here more than a week even reads
> his posts. Whatever the reason, it's not worth time even reading, much
> less answering, posts with his name on it. It's like optimizing a program:
> don't waste time on the areas where your work won't make any difference.
> Nothing personal, just that measurement has shown that effort spent
> answering his posts is wasteful.
Sometimes Bill's posts start a discussion on some aspect or other that may
be of interest to others reading the newsgroup.
Although the meaning of ^ and | probably isn't one of those..
--
bartc
|
|
0
|
|
|
|
Reply
|
bc (2211)
|
9/14/2008 1:30:23 PM
|
|
|
41 Replies
40 Views
(page loaded in 0.344 seconds)
|