logo

Hi 🔥 I'm YoTi

I’m on a serious journey to genuinely master the “C lang”, not just to write it.

"1.1 - Information Is Bits"

2024-08-23

The "hello world" program.

#include <stdio.h>
int main() {
    printf("hello, world\n");
}

When you write the "hello world" program, you create a file called hello.c using a text editor. This file is known as the source program, and it’s saved as a sequence of bits, where each bit is either a 0 or a 1. These bits are grouped into 8-bit chunks called bytes, and each byte represents a character in your program.

Modern systems usually represent characters using the ASCII standard, which assigns a unique number (or byte-sized integer value) to each character.

đź’ˇ Tip: You can see the ASCII values by typing man ascii in your terminal.

ASCII Table

This Figure shows the ASCII representation of the hello.c program.

ASCII representation of the hello.c program

In the hello.c file, each character is stored as a byte with a specific integer value. For example, the first character, #, is stored as the byte with the integer value 35. The second character, i, is stored as the byte with the value 105, and so on. Each line of text ends with an invisible newline character \n, which is represented by the integer value 10.

Files like hello.c, which consist only of ASCII characters, are called "text files." Files that aren't just ASCII characters are known as "binary files."

The way hello.c is stored highlights a key idea:

  • Everything in a computer system—whether it’s files on a disk, programs in memory, user data, or data sent over a network—is represented as bits.
  • What makes these bits different is the context in which they’re used. For example, the same sequence of bytes could represent a number, a string of text, or a machine instruction, depending on the situation.

As programmers, it's important to understand how computers represent numbers because they’re just approximations, and they can sometimes behave in unexpected ways.