• missing xbfish.com image
Programming
missing xbfish.com image
Posted on

Integer to Binary Conversion Part 2

This post is a continue from the previous post Integer to Binary Conversion Part 1.

missing xbfish.com image

Enhancement and Fix:
- Adding a menu system
- Overflow check

The code in C# :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
 
class Program {
    static void Main(string[] args) {
        int num = 0,  temp = 0, i = 0, menu = 0;
        int[] result = new int[8];
 
	printMenu();
        menu = readInt();
 
	while(menu != 0){
	   Console.WriteLine("Enter an integer to convert to binary:");
           num = readInt();
 
           if (num > 255) {
		Console.WriteLine("The integer exceeds the limit of 8 bits binary");
	   }else {
		Console.WriteLine("Converting..... The result is:");
		while (num != 0) {
		   temp = num % 2;
		   result[i] = temp;
		   num /= 2;
		   i++;
		}
		printResult(i, result);
	   } 
	   i = 0;
	   printMenu();
	   menu = readInt();
	}
    }
 
    public static int readInt(){
	return int.Parse(Console.ReadLine());
    }
 
    public static void printMenu() {
	Console.WriteLine("============ INTEGER TO BINARY CONVERTER  =============");
	Console.WriteLine("1. Press any number to convert Integer to 8 bits binary");
	Console.WriteLine("2. Press 0 to exit");
	Console.WriteLine("=======================================================");
	Console.WriteLine();
    }
 
    public static void printResult(int i, int []array) {
	Console.WriteLine("The 8 bits binary is: ");
	for(int k = (i - 1); k >= 0; k--){
            Console.Write(array[k]);
        }
	Console.WriteLine();
	Console.WriteLine();
    }
}

I will try to improve the code snippet when I have the time again… :)

Video
missing xbfish.com image
Posted on

天若有情 MV

Automotive
missing xbfish.com image
Posted on

Honda NSR150 SP CDI parts number

This is the OEM CDI for Honda NSR 150 SP :

missing xbfish.com image

Parts Number: 30410-KW6-841

Programming
missing xbfish.com image
Posted on

Styling input field when focus using CSS

Conventionally, the default styling for input can be ugly when you tried to click on it. Example of an default input field without any styling:

Example 1:

Now, lets give a “life” to the input field by styling it using CSS:

1
2
3
4
input:focus{
background-color: lightyellow;
border: 1px solid #CCC;
}

By styling all input fields, we can achieve the following effect when the textbox is being focus (or being click onto):

Example 2:

Notice the difference when you click on both of the textbox?

I hope this helps :)

Programming
missing xbfish.com image
Posted on

Integer to Binary Converter Part 1

Out of boredom, I write a code to convert Integer to Binary in C# :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
 
class Program {
    static void Main(string[] args) {
        int num = 0,  temp = 0, i = 0;
        int[] result = new int[8];
 
        Console.WriteLine("Enter an integer to convert to binary:");
        num = Int16.Parse(Console.ReadLine());
 
        Console.WriteLine("Converting..... The result is:");
        while (num != 0) {
            temp = num % 2;
            result[i] = temp;
            num /= 2; 
            i++;
        }
 
        // Printing out the answer 
        for(int k = (i - 1); k >= 0; k--){
            Console.Write(result[k]);
        }
    }
}

As you can see, the code is relatively simple and doesn’t have any validation check for overflow. The shortfall of this code is that the largest binary that can be converted from integer is 1111 1111.

I will brush up the code when I am free again.

** Refer to the post Integer to Binary Conversion Part 2 for the improved code snippet.

Hardware
missing xbfish.com image
Posted on

Colorful keycaps for my Ducky mechanical keyboard

Before:
missing xbfish.com image

missing xbfish.com image

After:
missing xbfish.com image

missing xbfish.com image

How is the color combination? I find it quite weird though…

Hardware
missing xbfish.com image
Posted on

Getting off the glue of my white keycaps

I ordered this set of 108 white keycaps and found there is a lot of glue beneath those keycap!

Tsk tsk~

Life
missing xbfish.com image
Posted on

End of my last paper!

Phew!~

Finally, this marks the end of Academic Year 11/12 Semester 2 for me.

Time to start blogging again! :)

Life
missing xbfish.com image
Posted on

Too busy, nowadays!

Will be back writing more awesome posts after I finish my semester 2 at NUS!~

Thanks for the donation!

Keep it coming! :D

Biz Concepts
missing xbfish.com image
Posted on

How Carlos Ghosn Led Nissan’s Turnaround

A very insightful video on how Carlos Ghosn managed the Japanese company and its employees: