home comics writing pictures archive about

2021-10-31 - DataTypes: Logical Values

Last time we looked at bits, binary digits, which can be either a 0 or a 1. Now the question is what can we do with these bits? Well the simplest thing we can do is treat them as logical or boolean values (named after George Boole and the system of Boolean algebra he developed). These can be either true or false. Many languages have a bool or boolean type which is used to hold these kinds of values. There’s a simple mapping between logical values and bits as both have only two possible values. Typically true is represented with and 1 and false with a 0 but this is entirely arbitrary. Collections of bits can be used to store a collection of logical values called bit flags or a boolean array.

Logical values are the basis for allowing computers to store state and make decisions. We can use a logical value to keep track of whether or not the oven is on and to perform a certain set of operations, like cooking a turkey, if it is and a different set if it isn’t, like turning it on. If the oven being on was currently false the computer would turn it on and then set the value to true. Now if the computer did the oven check again it would see it was true and cook the turkey. The computer could also have a loop that repeatedly checks to see if the turkey is cooked and once that becomes true it would take the turkey out of the oven and turn it off. These decision making and looping mechanisms are what allow computers to be smart. Without them they would be limited to simply performing the same set of operations every time.

Logical values can also be combined using various logical operators to produce new logical values that can be used for more complex decision making.

Not

The inverse, complement or not operation changes one logical value to the other. This allows you to perform an operation if a value isn’t true. (Not Hot) would be false if Hot was true.

Input Output
True False
False True

And

The and operation combines multiple inputs and is true only if all the inputs are true. This allows you perform a specific operation only if a variety of conditions are all true. (Hot and Humid) would be true only if Hot and Humid were both true.

Input 1 Input 2 Output
False False False
False True False
True False False
True True True

Or

The or operation combines multiple inputs and is true if any of the inputs are true. This allows an operation to be performed if at least one of the conditions is true. (Hot or Humid) would be true if either Hot or Humid was true.

Input 1 Input 2 Output
False False False
False True True
True False True
True True True

Xor

The exclusive-or operation is similar to or but is false if multiple inputs are also true. This allows an operation to be performed if only a single condition is true. (Hot xor Humid) would be true if Hot was true or if Humid was true but not if both were true.

Input 1 Input 2 Output
False False False
False True True
True False True
True True False

Logical values are useful for storing simple state information but to really do stuff with computers we need the ability to store more complex information. Next time we’re going to look at integer values.

2021-09-25 - Terrible with Dates

I like to think my memory is pretty good. I can remember song lyrics and movie quotes. I can remember classes, function names and programming concepts. I can imagine locations in my head. I can remember math and physics concepts even if I haven’t used them in a while, but I am terrible at remembering dates.

It seems like my brain strips away date information from whatever I’ve learned. It could be a historical fact or personal information. It could be something that happened to me. I can remember the event but for some reason I have difficulty recalling when it happened. Not only that but I have a hard time keeping track of the order of events. Did I go visit my parents before or after I got a hair cut?

It seems like my brain prefers to arrange information based on a physical rather than a chronological similarities. I can picture most of the houses I’ve lived in and where everything would have been but I struggle to recall when we would have moved into them. If you ask me where something is I might be able to figure it out but if you ask me when something happened or if one thing happened before another I probably won’t be able to tell you.

I think some of this is because of my eyes. Not being able to see well, I have learned to focus on and memorize where things are and what they look like. That way I can easily find those things even if I can’t really see them. I can navigate through a place or recognize something from far away. Concentrating on the physical aspects of things has probably made me less aware of the timing of things as that’s less critical to me.

I also notice that I’m better at remember what something looks like then what happened at an event. I can tell stories fairly well, I think, but I can’t recall them. If you ask me what happened I’d probably say “I don’t know”.

Another of those brain oddities.

2021-08-27 - Goals

I’ve been contemplating goals a lot lately. It seems like goals can be both good and bad depending how you set them. They can help you get stuff done while at the same time discouraging you from doing things.

On the positive side, goals are good for making sure you know what to do. Having a plan for your career, hobbies, life etc. If your goals are short term they can provide with options when you are contemplating what to do with your spare time and then make you feel more accomplished when you complete them. If your goals are long term they can give you direction and tell you what to work for.

On the negative side, they can be discouraging if it’s not clear how to accomplish them. If a goal is difficult or requires a lot of luck it can be easy to not even try. They can also make your other accomplishments feel less impressive because they aren’t what you’re supposed to be doing.

It seems like the further out your goals are the more vague they need to be. Don’t set yourself an absolute target far away instead try to set a general direction you want to go in. Figure out a few things that you can do along that path but don’t set up too many things upfront. Complete those tasks, see where you are, figure out where you want to go and make some more tasks.

You may not end up where you originally planned to go but you should at least end up going somewhere.

2021-06-06 - In IL: Class Definitions

IL is a object oriented language like C# and Visual Basic .Net. This means that classes are a built in concept. Classes are defined with a class header describing the class followed by a class body enclosed in curly braces.

.class <attributes..> <Id> extends <baseClas> implements <interfaces…>{ }

A class is declared using the .class directive. This is followed by a set of attributes which describe how the class behaves. The Id is the name of the class. The extends keyword is used to specific the base class. If no base class is provided system.Object is assumed. The implements keyword is used to specify which interfaces the class supports.

There are a variety of attributes that can be set.

Visibility

The visibility attributes are used for non-nested classes to indicate if they are exported, available, outside the assembly or not.

Attribute Description
private Class is not exported outside assembly
public Class is exported outside assembly

Accessibility

The accessibility attributes are used for nested classes to indicate if they are available to other classes.

Attribute Description
nested private Visible only within the containing class
nested famandassem Visible to containing class and derived classes within the same assembly
nested assembly Visible to the containing assembly
nested family Visibility to containing class and derived classes
nested famorassem Visibility to containing class and derived classes or to the containing assembly
nested public Visible everywhere

Layout

The layout attributes control how the fields of the class will be laid out in memory

Attribute Description
auto Layout of fields in the class is determined by the runtime
sequential Layout of fields will be sequential based on order of the fields in the class
explicit Layout of fields in the class will be set explicitly

Type

The type attribute is used to specify what type of class is being defined

Attribute Description
interface Class is an interface

Inheritance

Inheritance attributes control how a class can be used

Attribute Description
abstract Class cannot be instantiated
sealed Class cannot be derived from

Interpolation

Interpolation attributes control how the class is handled when interacting with unmanaged code. Specifically it controls how strings contained in the class will be marshalled, packaged, before being sent to the unmanaged code.

Attribute Description
autochar string marshalling is determined by platform
ansi Marshalled using ansi strings
unicode Marshalled using UTF-16 strings

Special

Special attributes are used by the runtime or tool to control how the class will be treated

Attribute Description
beforefieldinit Don’t initialize fields before a static call
serializable fields can be serialized (reserved)
rtspecialname Name has special meaning to the runtime
specialname Name has special meaning to tools
Prev page

3 4 5 6 7

Prev page