Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 19th, 2004, 12:40 PM   #11
mici
Programmer
 
Join Date: Oct 2004
Posts: 67
Rep Power: 4 mici is on a distinguished road
Yeah I guess thats true... never had much interest in binary math.
I rather use ints or hex.
__________________
coffee is my heroin.
mici is offline   Reply With Quote
Old Oct 19th, 2004, 12:52 PM   #12
Daggerhex_Flynn
Programmer
 
Join Date: Oct 2004
Location: Canada
Posts: 82
Rep Power: 4 Daggerhex_Flynn is on a distinguished road
Quote:
Originally posted by mici@Oct 19 2004, 05:40 PM
Yeah I guess thats true... never had much interest in binary math.
I rather use ints or hex.
Binary and Hex are both damn important. Apparently two's compliment is used because processors can recognize, and add two signed numbers efficiently and rapidly. For example, if the leftmost bit is a 0, than the number is positive, and if the leftmost bit is a 1, than the number is negative.

0110 0010 = positve
1000 1010 = negative

And the positive is always a straight calculation, while the negative is a quick inverse, followed by adding one, and than make the value negative.
Daggerhex_Flynn is offline   Reply With Quote
Old Oct 19th, 2004, 1:21 PM   #13
mici
Programmer
 
Join Date: Oct 2004
Posts: 67
Rep Power: 4 mici is on a distinguished road
My mistake!
__________________
coffee is my heroin.
mici is offline   Reply With Quote
Old Oct 19th, 2004, 3:46 PM   #14
sys0p
Programmer
 
Join Date: Oct 2004
Posts: 73
Rep Power: 4 sys0p is on a distinguished road
Quote:

Yes but only if the name has been defined as char, uint8 and so on...
(i.e. char name[100]
However if the name has been defined as int (i.e. int name[100])
then it would look like this:

name[0]=0x1000
name[1]=0x1002
name[2]=0x1004

explanation:
unsigned char takes one byte and can hold value between 0 and 255 (2^8)
unsigned int takes two bytes and can hold value between 0 and 65536 (2^16)
unsigned double takes 4 bytes ... and so on.
signed versions have the same field of values but it starts with -max/2 and ends with max/2
(i.e. min = -128 max =128)

OK dude, I see! Ta for explaining!

Quote:

-max/2 and ends with max/2
You mean -min/2 ...

It's OK. I know you are tired!

Quote:

btw.
I'm absolutly fascinated with your avatar.
Yeah it's a fine one!

And just to make sure I understand, is this right:

If we run the following on the command line:

myBigProgram.exe -l 66 -n program.txt

It will look like this:

argc = 5
argv[0] = "myBigProgram.exe";
argv[1] = "-l"
argv[2] = 66
argv[3] = "-n"
argv[4] = "program.txt"

argv[0][0] = 'm'
argv[0][1] = 'y'
argv[0][2] = 'B'
argv[0][3] = 'i'
argv[0][4] = 'g'
argv[0][5] = 'P'
argv[0][6] = 'r'
argv[0][7] = 'o'
argv[0][8] = 'g'
argv[0][9] = 'r'
argv[0][10] = 'a'
argv[0][11] = 'm'
argv[0][12] = '.'
argv[0][13] = 'e'
argv[0][14] = 'x'
argv[0][15] = 'e'

argv[1][0] = '-'
argv[1][1] = 'l'

argv[2][0] = '6' //Is this right, it is a number
argv[2][1] = '6' //Is this right, it is a number

argv[3][0] = '-'
argv[3][1] = 'n'

argv[4][0] = 'p'
argv[4][1] = 'r'
argv[4][2] = 'o'
argv[4][3] = 'g'
argv[4][4] = 'r'
argv[4][5] = 'a'
argv[4][6] = 'm'


I have a feeling this isn't right?

Anyway, thanks guys for your replies! Very much appreciated!
Cheers!

Quote:

My mistake!
What's that?
sys0p is offline   Reply With Quote
Old Oct 19th, 2004, 5:57 PM   #15
mici
Programmer
 
Join Date: Oct 2004
Posts: 67
Rep Power: 4 mici is on a distinguished road
Quote:

If we run the following on the command line:

myBigProgram.exe -l 66 -n program.txt

It will look like this:

argc = 5
argv[0] = "myBigProgram.exe";
argv[1] = "-l"
argv[2] = 66
argv[3] = "-n"
argv[4] = "program.txt"

argv[0][0] = 'm'
argv[0][1] = 'y'
argv[0][2] = 'B'
argv[0][3] = 'i'
argv[0][4] = 'g'
argv[0][5] = 'P'
argv[0][6] = 'r'
argv[0][7] = 'o'
argv[0][8] = 'g'
argv[0][9] = 'r'
argv[0][10] = 'a'
argv[0][11] = 'm'
argv[0][12] = '.'
argv[0][13] = 'e'
argv[0][14] = 'x'
argv[0][15] = 'e'

argv[1][0] = '-'
argv[1][1] = 'l'

argv[2][0] = '6' //Is this right, it is a number
argv[2][1] = '6' //Is this right, it is a number

argv[3][0] = '-'
argv[3][1] = 'n'

argv[4][0] = 'p'
argv[4][1] = 'r'
argv[4][2] = 'o'
argv[4][3] = 'g'
argv[4][4] = 'r'
argv[4][5] = 'a'
argv[4][6] = 'm'

You've got it right missy!
A- O.K. (couldn't be better, and I'm not saying that just because you have a nice a.. hmmm avatar).
Actualy doesn't matter if you type a number ... the system still reads it as a char ... later on you convert it with atoi() atof() etc. depending on what kind of num it is...

Quote:

You mean -min/2 ...

It's OK. I know you are tired!
once again...
no explanation required... you get the point...I'm still tired.

Quote:


My mistake!


What's that?
Refers to min and max values for signed chars... DaggerHex_Flyn calculated using binary values and the rule called "two's compliment" that the min value is -128 and max is 127...
(easiest explanation is that you have 256 available values when using 8 bits, out theese 256 values one of them has to be zero therefore it's not possible to have the same number of positive and negative values... thus 127)
If i wasn't clear ... no wories You realy don't need to know or understand this at this point... And if you do, good for you... now quickly forget it (format your drive ) or you'll have nightmares...I know i do... :blink:
__________________
coffee is my heroin.
mici is offline   Reply With Quote
Old Oct 19th, 2004, 8:37 PM   #16
Daggerhex_Flynn
Programmer
 
Join Date: Oct 2004
Location: Canada
Posts: 82
Rep Power: 4 Daggerhex_Flynn is on a distinguished road
I have to fix my screw up: Regarding two's compliment:
Maximum positive 8 bit# = 0111 1111 = 1+2+4+8+16+32+64+0 = 127
Simple enought
Maximum negative 8 bit# = 1000 0000 = 0111 1111 = 1000 0000 = 0+0+0+0+0+0+0+128 = -128

So it works perfectly, if you do your addition properly.
Daggerhex_Flynn is offline   Reply With Quote
Old Oct 20th, 2004, 12:07 AM   #17
sys0p
Programmer
 
Join Date: Oct 2004
Posts: 73
Rep Power: 4 sys0p is on a distinguished road
Quote:
now quickly forget it (format your drive ) or you'll have nightmares...I know i do...
Ha ha lol!

Sure will do. Thanks for the help guys! Very much appreciated.
Cheers
sys0p is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:44 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC