ALine Posted February 9, 2021 Posted February 9, 2021 In computer science how do you go from 1's and 0's to the different data types such as int, float, double, Boolean, etc? It is all just an upper level of abstraction? Is is a function at the lower functional hardware level of the computer? Does it somehow deal with the different flags in the hardware/software level boundary(do not know how else to put that)? Thank you for your responses.
Sensei Posted February 9, 2021 Posted February 9, 2021 (edited) Bit can contains value 0 or 1. If we group 8 bits it is byte. The all other data types have resolution in multiple of byte: 16 bits, 32 bits, 64 bits etc. From computer point of view they are always binary. If typical computer application must print number to user, it has to convert binary to decimal (for non-programmers). It is just on screen. Internally it is is still binary. Conversion takes CPU time and memory. In older times sometimes was used BCD. Now I think it is obsolete. https://en.m.wikipedia.org/wiki/Binary-coded_decimal It could be found in e.g. embedded systems. Display and basic maths are easier and takes less time than full binary to decimal conversion (because they need multiplication, division and/or modulo.. which maybe are not implemented in cheaper weaker chips e.g. Atari/C-64 CPU Motorola 6502/6510 don't have built-in multiplication, division and modulo instructions). 48 minutes ago, ALine said: Does it somehow deal with the different flags in the hardware/software level boundary(do not know how else to put that)? CPU has flags: zero, overflow, carry, nagative and others. Some CPU instructions modify some of these flags. Usually arithmetic instructions. If you subtract e.g. variable x0 from x1 (register from register/memory) and you get zero result there is set zero flag in CPU. What does it mean? That x0 was equal to x1. Therefore instructions to perform jumps are called je, jne, beq and bne. Shortcuts from Jump if Equal. Jump if Not Equal. Branch if EQual and Branch if Not Equal. They test state of zero flag in CPU. It is what is used by higher level languages if()/for()/while() etc. functions. And by Boolean to check its state and perform jump. What you see on the screen is just bunch of pixels with shape of digit. Edited February 9, 2021 by Sensei 2
ALine Posted February 9, 2021 Author Posted February 9, 2021 Ok, so those types have no inherent meaning besides just being pixel values on the screen and it all boils down to binary and their operations then if I'm understanding you correctly. Also thank you for the intro explanation which brought it all the way up from the 1s and 0s.
Sensei Posted February 9, 2021 Posted February 9, 2021 (edited) 1 hour ago, ALine said: Ok, so those types have no inherent meaning They have meaning. Integers are understood by ALU. Floats and doubles are understood by FPU. These days FPU is builtin CPU. But in '80 and early '90 in 386 and early 486 FPUs were external chipsets. Coprocessor. Floats are in IEEE 754 standard. https://en.m.wikipedia.org/wiki/IEEE_754 It is much harder to convert float or double to human readable format than plain integer. Therefore there is plentiful parameters which you need to bother about during conversion. Read printf/sprints C/C++ manual %f and %g. Edited February 9, 2021 by Sensei 1
ALine Posted February 9, 2021 Author Posted February 9, 2021 That is my first time actually hearing about an FPU, ok cool! Learned something new. Ok, I think I got a understanding for it. Thanks for the assist @Sensei
Sensei Posted February 9, 2021 Posted February 9, 2021 (edited) 16 minutes ago, ALine said: That is my first time actually hearing about an FPU, ok cool! Learned something new. FPU stands for Floating point unit. https://en.m.wikipedia.org/wiki/Floating-point_unit ALU stands for Arithmetic logic unit. https://en.m.wikipedia.org/wiki/Arithmetic_logic_unit If CPU has no builtin instructions which operate natively on the datatype, they need to simulate it in normal code. Such virtual datatypes are created in every C++ or Java project. Programmer-scientist usually needs to have limitless resolution of the number so needs to make (or find library with ready solution) which will allow much better precision than 64 bit integer to 64 bit double. CPU which has no FPU built-in nor external FPU had to simulate IEEE 754 in regular code. If you would like to have 128 bits or 256 bits floating point number you would have to make such code by yourself. It is kinda fun task. Edited February 9, 2021 by Sensei
ALine Posted February 9, 2021 Author Posted February 9, 2021 (edited) 50 minutes ago, Sensei said: It is kinda fun task. I am having a hard time just understanding data types, let alone getting to the skill level of programming my own libraries. That sounds like a "once I get a complete handle" on it kind of thing. Edited February 10, 2021 by ALine Said the same thing twice
Sensei Posted February 10, 2021 Posted February 10, 2021 (edited) 52 minutes ago, ALine said: I am having a hard time just understanding data types, let alone getting to the skill level of programming my own libraries. That sounds like a "once I get a complete handle" on it kind of thing. Don't try to understand, just use them.. You don't understand how computer works but still use it either. Understanding how something works grow together with the amount of stuff that you wrote (programmed). It is not heart surgery. Don't have to know how it works internally with great details. Bugs and problems are unavoidable and common day stuff for any programmer. The best programming tutorials for beginners IMHO are the one which explain "How to write app xxx". Because they are not boring. You immediately see effects. You repeat what tutor is presenting and together with him or her repeat line by line. Attempt to explain everything will lead to uberboring textbook. To store name you need e.g. string. In C++ you write: std::string first_name; Then you need to have surname: std::string surname; Then you need age. Age is integer with years. int age; put them in separate class together: class Person { std::string first_name; std::string surname; int age; } You need to create object of this class so you use: Person *person = new Person(); and you need to initialize it: person->first_name="John"; person->surname="Doe"; person->age=34; Abstract/custom data type. For app which stores people data. You don't need to know how std::string was implemented. And you will never know it. It is blackbox. You can only know what methods and fields were exposed to public and read about their parameters and properties in the reference. Edited February 10, 2021 by Sensei
ALine Posted February 10, 2021 Author Posted February 10, 2021 4 minutes ago, Sensei said: You don't need to know how std::string was implemented. And you will never know it. It is blackbox. You can only know what methods and fields were exposed to public and read about their parameters and properties in the reference. This is both reassuring and disheartening. My biggest problem is that I enjoy how the black box works and want to learn more, but when I look under the hood I get into theory which is boring your right. Its like a never ending game of "ohh a piece of candy" grabs candy and realize it's a grandma mint.
Holmes Posted July 4, 2021 Posted July 4, 2021 (edited) On 2/9/2021 at 12:28 PM, ALine said: In computer science how do you go from 1's and 0's to the different data types such as int, float, double, Boolean, etc? It is all just an upper level of abstraction? Is is a function at the lower functional hardware level of the computer? Does it somehow deal with the different flags in the hardware/software level boundary(do not know how else to put that)? Thank you for your responses. The types to refer to are technically classes of finite state machines, all of them can be represented as state machines (and in most cases this is implemented in hardware). Take "int" ultimately this is just a set of bits but how the bits change over time as events occur is defined by a state machine. This is my answer, it may not be obvious but I think it goes to he heart of what you're asking. Edited July 4, 2021 by Holmes
Kartazion Posted July 4, 2021 Posted July 4, 2021 On 2/9/2021 at 8:28 PM, ALine said: In computer science how do you go from 1's and 0's to the different data types such as int, float, double, Boolean, etc? It is all just an upper level of abstraction? Is is a function at the lower functional hardware level of the computer? This is the role of the compiler. Early computer software was written in assembly language corresponding to processor instructions, and early compilers were written directly in assembly language. In general, the source language is "higher level" than the target language, that is, it presents a high-level of abstraction. An interpreted language as JavaScript, Python, Perl, etc, is a programming language which are generally interpreted, without compiling a program but instead read and executed by some other program. On 2/9/2021 at 8:28 PM, ALine said: Does it somehow deal with the different flags in the hardware/software level boundary(do not know how else to put that)? Thank you for your responses. AFAIN not really. The flags is an additional processor informations. It allows you to set and know the state of the processor at any time thanks to the different bits that compose it. This register thus makes it possible to have at any time the state resulting from an instruction having been executed by the processor. FLAGS register - Wikipedia
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now