Types, Integral Types, Bytes?!?!?!

This is a discussion on Types, Integral Types, Bytes?!?!?! within the C++ Programming forums, part of the General Programming Boards category; Hey guys, I was reading the C++ Primer book, and I just got to Chapter 2, and I'm confused. . ...

Types, Integral Types, Bytes?!?!?!

Hey guys, I was reading the C++ Primer book, and I just got to Chapter 2, and I'm confused. . The beginning of the Chapter where it's talking about integral types, bytes, integers, etc. is really confusing. Like, I understand that different types store different information, but one of the practice questions asks what the range of integers are allowed in a 8 bit short type. What....?

Hmm, maybe I'm too dumb to get into this . But no, I'm not giving up. If any of you can give me an explanation or a URL to an article or something talking about this in a clearer way, please do so, and thanks.

Also, one of the exercises in the book asks you to write a program to let the user input a series of numbers, and then print out how many negative numbers were put in. I tried this, and all I could manage was for it to print out the value of the negative number, but not how many negative numbers there are. Could someone help me with this please? Since my computer that I write code on is different from this computer, I can't be sure that this is the code I wrote, but I think this is it.

Also, when I run a program (from the compiler), and there's any input at all, when you push enter to submit your input, the program will close automatically. Is there any piece of code to get around this?

Thanks a lot madcow, but can you tell me how you got the number 255? Thanks again.

regarding bits it's not entirely important but the way bits work is pretty simple

Let's say a number is 'n' bits.
Signed (+ & -) 'n' bit number can represent a range from: -2^(n-1)...+2^(n-1)-1
Signed 'n' bit numbers represent a range from: 0...+2^(n)-1

That means an 8 bit signed integer ranges from -128...127, and an 8 bit unsigned int goes from 0 through 255

In both cases they have 256 possible values (0 inclusive no?)

I've only really had to know this for assembly which relies bit ranges and such.

Originally Posted by Kaidao

Also, when I run a program (from the compiler), and there's any input at all, when you push enter to submit your input, the program will close automatically. Is there any piece of code to get around this?

Thanks a lot madcow, but can you tell me how you got the number 255? Thanks again.