How values are stored in binary form in memory? C Programming.

It can take 256 functions, eight bits of input. Okay. Now, if you have like that, then you pretty much know that this cannot be a signed bit because the moment you want to send the data, it will say, Oh, I got 1 here right now Right. Now, if you write one here, if it’s a negative number, one is a negative number For C programming. So you’re really wasting and you’re confusing the controller right, because controller says, Yeah, this is more like a reset function. When you say all 0-0-0 may be pretty much like a reset or the 0-0-0-0-1, then 0-0-2 and then three. So many value you have, you can have 2 56 command values for the controller. So essentially, think about the programming where the programming requirements are different because the hardware right.

Hardware doesn’t understand negative numbers. How do I say I have a controller function and then function zero or 1 or two or 3 4. And so and so forth. Think about printer programming. So it’s a printer. Let’s say 1, 1 means I want to take a photocopy. So I really want to take a photocopy with function one and then function two on a printer. You say I want to do scanning of the documents. I’m doing a scanning, and then function 3, maybe I want to do a Fax. Right. So you want to send a Fax so you can have any functions for your embedded programs.

When you’re interfacing with your computer. So when you do a C programming, always remember that controllers’ processor, they don’t understand negative number for their input functions. Okay. So invariably character is ruled out. Yes, you can’t have character or no, the only choice is remembering programming. We should have an unsigned Char unsigned character for it. Right. So some of you are from the industry or going to join the industry. Right. So there is a special typedef I have not covered typedef, but this is a good example to explain. In the typesets world, we always write the unsigned character as some sort of, you know u8 So you define an u8. It basically means it’s unsigned. And then the programming guidelines and coding guidelines for that company. Think about the automotive industry.

Think about a lot of these embedded environments. They will never allow you to use a fundamental data type. They say, no, you have to use the one that is governed by the programming disciplines, programming guidelines of that company. So when you want to declare a register variable, you say, I have a control reg2 Right. Because by doing this, you’re anyway internally defining an unsigned character. Right. So this is what we do. So, again, this is a long answer to that original problem. Right. Okay. So let’s come back into the class and you know the reason why, why we have the answers. So even though you don’t have 256 functions for your controller or your processor in the microprocessor.

You’re never going to declare a programming construct in C saying that it’s a signed value because it just doesn’t serve the purpose, it will confuse the controller more than anything else. Right. Okay. So the answer is unsigned character. Now, here again, what is the focus? The focus is on the right choice for your programming variable for a lot of these programming designs. Right. Code can be good. And if the variables are not good, the program just won’t work, actually. Okay. So look into the third one. Now, this is a very interesting question.

Which data type is most suitable to restore the length of a string. Right. So I’m now a programmer and especially a C programmer at this point. Right. We have to be very careful about the return values. A lot of high-level programming languages, just don’t care. They don’t bother about all these things because high-level programming languages solve a very different problem. Okay. The focus is on a very big picture, and they don’t worry about wasting a lot of stages. They don’t worry about wasting a lot of space. Okay. A lot of memory locations. But C is not like that. C is exactly what you wanted to do. So, C, we have to focus on memory. We have to focus on efficient memory utilization with a very small piece of memory. We can do wonders. That’s the whole idea. So string length function. Why I have chosen this example because I think every programmer in the world knows what is STR length. String length.

There are a lot of casual programmers and serious programmers, but when you want the length you want to string length, you use string length. Let’s look into that. If you already know the answer, we will cover a little more. Okay. If you already know the answer, my promise is I’ll explain something more about it. And if you don’t know the answer anyway, here we go. So which data type is more suitable for storing the length of a string? Int unsigned int, long, and unsigned long. The answer is unsigned long. But if you already know the real logic behind it, then it’s pretty good. But I will explain more than why the answer is unsigned long at this point. Okay. So let’s go into the scratchpad and try to understand more. Now, I think it’s easy for us to relate. It’s easy for us to relate to. Let me duplicate it once.

Remember the live class. So you have to always bear with me for some time. Okay. And my promise to explain as much as I can. So fundamental question, length of string, size of any object. Think about this kind of programming requirement. Length of something. Right. String means I’m looking at maybe something or any object means any object, something. The fundamental question is, can the length be negative? Can the size be negative?

The only answer is, it cannot be negative. So what do we rule out? We rule all the signed versions of the choices it cannot be, and it cannot belong. And I told you, I think when you write int or long, especially in the implementation of C language. Right. When you say int or long by default, they are. They are signed. So this is ruled out. So what we are left with, we are left with unsigned versions, unsigned versions of Int, and unsigned long. Yeah. So for a lot of casual programmers, and which is true, not a bad deal, actually.

Leave a Comment