## What Are Prerequisites Before Embedded Programming?

Following are the prerequisites need to be covered before jumping into sea of embedded programming.

1. Binary Numbering System

2. Bitwise operators

3. Unsafe Rust

4. Raw Pointers

5. Mutable Static variables

### Binary Number System

Keep the points in mind in sequence.Binary numbers are made up of only 1’s and 0’s. They don’t contain any other number we usually see in decimals (i.e. 2,3,4,...,9). Here are few examples.

 Decimal 0 1 2 4 13 21 27 45 Binary 0 1 10 100 1101 10101 11011 101101

Binary numbers have base of 2 in contrast our decimal numbers which have base 10. What base tells us? It tells how many combination can a number give us.

 Decimal Binary 0000 Starts at 0 0000 Starts at 0 0009 Goes upto 9 0001 Goes upto 1 0010 Reset the digit and increment the next digit. 0010 Reset the current digit and increment the next 0019 Again goes upto 9 0011 What happens next? 0099 What happens with 99, now 2 digits are at optimum 0100 Initial 2 digits got reset and next digit will be incremented 0100 Both will got reset and next digit will  be incremented.

### Bitwise Operator

Wondering! What these are? Now we are familiar with binary numbers. Next we will see concept of Bitwise operators that based on the binary numbers. There are variety of operators in programming languages (i.e. arithmetic, relational, logical and assignment operators). Bitwise operator is one of them.

Bitwise AND ( & )

It do a Boolean AND operation on each bit of its integer arguments.

Bitwise OR ( | )

This perform a Boolean OR operation on each bit of its integer arguments.

Bitwise XOR ( ^ )

It do a Boolean exclusive OR operation on each bit of its integer arguments.

Bitwise NOT ( ! )

This is an unary operator and operates by reversing all the bits in the operand.

Bitwise left shift ( << )

It moves all the bits in its first operand to the left by the number of places specified in the second operand.

Bitwise right shift ( >> )

Binary Right Shift Operator.

### Unsafe Rust

What is that?

6. Hidden language inside Rust

7. Gives us extra superpowers

Why is it?
• It let us do the operations which compiler restricts us from

• Without unsafe Rust we can’t do operations on hardware level

Unsafe Superpowers:
• De-reference a raw pointer

• Call an unsafe function or method

• Access or modify a mutable static variable

• Implement an unsafe trait

Keep few things in mind while using unsafe Rust :

• Unsafe rust doesn’t disable borrow checker or any other safety feature.

• It gives you only access to these four features and compiler don’t check for memory safety in them.

• Inside unsafe block the code doesn’t need to be necessarily dangerous.

• While writing code keep the unsafe block smaller.

• For the isolation of unsafe code, it’s better to enclose unsafe code with in a safe abstraction. Wrapper!

• When using unsafe rust we as programmer have to ensure that you are accessing memory in a valid way.

### Raw pointer

There are two new typs of Unsafe Rus called raw pointers that are similar to references. They can be immutable or mutable and can be written as:

• *const T (Immutable)

• *mut T (Mutable)

Note: Asterisk “ * ” is not a de-referencing operator, it’s part of type name. Let’s see how to create an immutable and mutable raw pointer from reference.                        let mut num = 5;

let r1=&num as *const i32;

let r2=&mut num as *mut i32;
Is something wrong! We didn’t include unsafe keyword here? Well, its okay to create raw pointers outside unsafe but it’s must to include while de-referencing them.

How raw pointers different from references!

• Are allowed to ignore the borrowing rules by having both immutable and mutable pointers or multiple mutable pointers to the same location

• Aren’t guaranteed to point to valid memory

• Are allowed to be null

• Don’t implement any automatic cleanup

### Static variables

• Global variables in Rust are called static variables

• Static variables are similar to Constants

• Naming style of static variables is in SCREAMING_SNAKE_CASE

• Type annotation for static variables is must (like constants).

• Rust allows access read-only static variables (immutable static variables ), however doesn’t allow access to immutable static variables.

Static variables always have fixed address in memory.

### What is Internet of Things (IoT)?

What is Internet of Things (IoT)?    The internet of Things, or IoT, refers to the billions of physical devices  round the  world that are now connected to  the web  , collecting, sharing and analyses  of knowledge  . It presents and provides the explanation of the network of physical things which is embedded with software , sensors,  and other technologies for the benefit of connecting and exchanging data with other devices and systems on the internet   . Due to the cheap processors and wireless networks, it's possible to  means  anything, from a pill to an aero plane to a self-driving car into  an area  of the IoT. Overview IoT will control the Fourth  technological revolution  . The Fourth  technological revolution  is changing the very software-defined automation allows manufacturers to link all stages of  the worth  chain, rapidly adapt to changing markets , and make highly personalized products on a mass scale. The opportunities provided by this revolution are authenticated

### What is Rust Borrowing?

What is Rust Borrowing? Borrowing We call having references as function parameters borrowing. As in real world , if an individual owns something, we 'll borrow it from them . Whenever we’re done, we 've got to offer it back. Referencing  The reference is that the act of consulting somebody or something so as to urge information We would  declare reference in terms of Rust programing as if we are taking a replica of it without damaging or taking its ownership. ‘&’ symbol is employed to pass the reference Have a look that  how ‘&’ symbol is employed in code. fn main() { let s1 = String::from("hello"); let len = calculate_length(&s1); println!("The length of {} is {}.", s1, len); } fn calculate_length(s: &String) -> usize { s.len()} Mutable References The actual concept of mutable reference is same as we use mutable variable When  we  need to  modify  mutable reference is employed once   the worth we make regard to.