Tag Info

Hot answers tagged

56

Of course it is possible, both theoretically and practically. Theoretically, there are two classes of alternatives: digital number systems with a base other than 2 (in fact, the decimal system as we know it is one such system); and non-digital number systems. Mathematically speaking, we're talking about discrete vs. continuous domains. In practice, both ...


31

A lot of really early work was done with 5-bit baudot codes, but those quickly became quite limiting (only 32 possible characters, so basically only upper-case letters, and a few punctuation marks, but not enough "space" for digits). From there, quite a few machines went to 6-bit characters. This was still pretty inadequate though -- if you wanted upper- ...


28

Your argumentation against floating point numbers is very fragile, probably because of naivety. (No offense here, I find your question is actually very interesting, I hope my answer will also be.) A classic argument is that floats provide a greater range, but high precision integers can meet this challenge now. For example: with modern 64-bit ...


26

No, in fact this is how many file formats work. Common examples of binary files like this include images and music/audio files. To maintain the integrity of the file and the data read from it, be sure to follow these guidelines: Always open the file (reading or writing) using the same mode: text or binary. The primary difference is text mode cares about ...


21

Those are called qubits, and are used in quantum computers. You'll find more information about them on the wikipedia entry. Research is being done to make such computers that are stable and economically feasible.


21

You're basically describing an analog signal, which are used in sensors, but rarely for internal computations. The problem is noise degrades the quality, you need very precise calibration of a reference point that is difficult to communicate, and transmission is a problem because it loses strength the farther it travels. If you're interested in exploring ...


21

Because switching to integers doesn't solve anything. The problem with floats isn't that they have inaccuracies, it's that half the people using them don't pay any attention to what's going on. Those same people aren't going to pay proper attention to the units they are using when they use an integer, and a different set of screw ups will happen. Repeat ...


19

Physical characteristics of the universe (like the number of atoms in it) are not useful to determine the boundaries of number sizes, because useful calculations exist using numbers having wider ranges. Floating point numbers are a tradeoff between accuracy and range. They deliberately give up some accuracy to achieve greater range.


17

A matter of accuracy One reason we use bits is that it helps us store and retrieve information accurately. The real world is analog, therefore all the information computers pass or store is ultimately analog. For example, a current of a specific voltage on a wire, or magnetic charge of a specific strength on a disk, or a pit of a specific depth on a laser ...


14

Because most of the processors that you use in your day to day life are not modern day 64 bit processors with crazy fast integer calculations or an over abundance of space. Most of your processors are 8-16 bit devices which run things like your car, microwave, or watch. Besides, what happens when you need to talk about a half of a unit, like a half of a ...


11

The problem is the line byte q1 = keyboard.nextByte() * 10;. There are no arithmetic operations on byte or short. The value of keyboard.nextByte() is casted up to an int prior to multiplication with 10, which is also an int. The result of the multiplication is an int, which can not be stored into q1 if it's defined as a byte. Possible solutions would be to ...


11

The only danger you will run into is little vs. big endianess (whether the most or least significant byte is written first). However if you remain in the same environment there will be no issue. besides the general ensuring of writing/parsing roundtrip. The file system is designed to handle any sequence of bytes.


10

AFAIK, no answers presented here are correct. The size of bool and _Bool is not constrained to be 1 byte (I seem to remember that there is a constraint in C which forces sizeof(_Bool)<=sizeof(short) which hasn't an equivalent in C++)


10

Is the ID always in the form: IO123456? What your colleague could mean is that he only sends the numeric part, which fits easily in 4 bytes omitting the "IO" part.


10

There are also ternary computers instead of binary ones. http://en.wikipedia.org/wiki/Ternary_computer A ternary computer (also called trinary computer) is a computer that uses ternary logic (three possible values) instead of the more common binary logic (two possible values) in its calculations...


10

Using a float instead of a high precision integer (with conversions!) is simply easier and faster. I can type in float myVar = 0.15; //my value... and move on to the rest of the logic of my simulation. I don't have to spend extra time thinking about converting to int and making sure that all of my scales are correct. And the results end up being good ...


10

I'm working on a report as I type this. One of the fields is a long milliseconds of duration that I got from somewhere else. This is going to be sent to Microsoft Excel and the duration units it uses is decimal days (1.25 = 1 day, 6 hours). Sure, you can subdivide a range from the lowest possible value to the largest and have integer units stepping ...


9

You need log2(n) bits to address n bytes. For example, you can store 256 different values in an 8 bit number, so 8 bits can address 256 bytes. 210 = 1024, so you need 10 bits to address every byte in a kilobyte. Likewise, you need 20 bits to address every byte in a megabyte, and 30 bits to address every byte in a gigabyte. 232 = 4294967296, which is the ...


9

The abbreviations for bits and bytes are differentiated by their case: lower case (b) means bits and upper case (B) means bytes.


9

In the hopes of giving you a better idea of how this all works together, I'm going to break this down into a few different sections. Feel free to skip sections you feel confident you know enough about. Operating Systems Operating systems are large pieces of software that manage the resources of the computer and allocate them out to other applications ...


9

How do I tell a user that one means bits per second while the other means bytes per second and how would I style the lettering Seems like this is one of those things that you get to decide as the designer of the program. There are lots of options, including but not limited to: spell it out: Eliminate the ambiguity by simply writing "bytes/sec" or ...


9

In addition to all of the gotchas already mentioned, if you are making up a new binary file format rather than reading and writing data in an existing format, it is absolutely vital that you include a file header: a block of data at the very beginning of the file that unambiguously identifies the file format and records any metadata that may be required. ...


8

The Java language has a lot of historical baggage. In Java, everything is an object – with the exception of primitive types such as int or byte that represent C-like value types. While these primitives are generally more efficient, they have some serious restrictions: You can't call methods on non-objects. There is a compiler technique called “autoboxing” ...


6

If the first two characters are not constant (but are always letters) and the remaining six characters are always numbers, a string like "IO123456" can be packed into 5 bytes by converting the numbers into binary-coded decimal (BCD) format: IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36 | | \ / \ / \ / ...


6

Seven bits for ASCII information, and one for error-detecting parity.


4

It might well be more natural to us but there are specific reasons why binary was chosen for digital circuitry and thereby for programming languages. If you have two states you only need to distinguish between two volt settings say 0V and 5V. For each additional increase to the radix (base) you'd need to further divide that range thus getting values that are ...


4

I'd say the answers are both D) but the questions do leave a bit to be desired, for the first as AProgrammer points out, a bool could be bigger than 1 byte, for the second question it should clarify the smallest unit of addressable memory (bitfields allow a structure of multiple smaller memory units but they aren't addressable) to clarify why C) is not the ...


4

Because sometimes even a 64-bit integer won't give you enough range. For example, in the physics code I'm currently working on, I need to convert some molecular masses between grams per mole (which the input / output format uses) and kilograms per molecule (which the internal calculations need for unit consistency). There are about 279 molecules in a mole, ...


4

InputStream itself is already an abstraction of a stream of bytes that can be read. A ByteArrayInputStream is a specific implementation of InputStream that gets the bytes in the stream from an underlying byte array (that's the one the constructor wants you to supply). For your method here, there is probably not much benefit in having a ByteArrayInputStream, ...


3

Existing answers have explained that the formula for addressing ram is 2^BITS = Addressable ram, but have not explained why. Consider a system with 2 bits. It can address 4 bytes of ram as follows: Byte 0: 00 Byte 1: 01 Byte 2: 10 Byte 3: 11 For each additional bit, we can address twice as much memory. E.g., add a 0 bit to each for bytes 0-3, then add ...



Only top voted, non community-wiki answers of a minimum length are eligible