Saturday, 1 August 2020

Direct Conversion From Any Number Base To Another Base Explained

Let's consider that we need to convert a base 4 number to base 8 number.
Base 4 digits: 0 1 2 3
Base 8 digits: 0 1 2 3 4 5 6 7
We should build a chart to map all digits in base 8 to its equivalent number in base 4. That will come in handy.
So how do we do that? Looks like we need to do conversion from base 8 to base 4 first.
So here are the steps to follow:
  1. Divide the number to be converted (base 8) by the value of other base (4).
  2. Get the remainder. That is the least significant digit.
  3. Divide the quotient with the same value (4).
  4. Add the remainder as next least significant digit.
Keep doing steps 3 & 4 repeatedly till quotient becomes zero.  Now let's understand it with the example.
We need to convert 4, 5, 6, 7 to its equivalent base 4 number.

For 4:
      4 % 4 = 0, 4 / 4 = 1,
      1 % 4 = 1, 1 / 4 = 0
      So base 4 equivalent of 4 (base 8) is 10

For 5:
      5 % 4 = 1, 5 / 4 = 1
      1 % 4 = 1, 1 / 4 = 0
      So base 4 equivalent of 5 (base 8) is 11

For 6:
      6 % 4 = 2, 6 / 4 = 1
      1 % 4 = 1, 1 / 4 = 0
      So base 4 equivalent of 6 (base 8) is 12

For 7:
       7 % 4 = 3, 7 / 4 = 1
       1 % 4 = 1, 1 / 4 = 0
       So base 4 equivalent of 7 (base 8) is 13

Actually now you have learnt how to directly convert upper base numbers (base 8) to lower base numbers (base 4).
So what's the difference when we convert lower base (base 4) numbers to upper base (base 8)?
Just to remind, we were doing arithmetic operations in base 8 number system. As all digits of base 4 are already present in base 8 number system, we didn't have to do any extra step.
To convert from base 4 to base 8, we will be doing operations in base 4 number system. We need to divide the base 4 number by 8 which is the value of base we are converting to. But 8 is not present in base 4 system. And possible remainders can be 4, 5, 6, 7. So we need to find equivalent values for these numbers in base 4 system.
For 4, 5, 6, 7 we have already done that above.

Let's find equivalent of 8 (base 10) in base 4 system.
8 % 4 = 0, 8 / 4 = 2,
2 % 4 = 2, 2 / 4 = 0
So base 4 equivalent of number 8 (base 10) is 20.

Now we will convert 3211 in base 4 to its equivalent in base 8. Here is the hard part. We need to do the calculation in base 4 system.

Multiplication table:
1 * 20 = 20
2 * 20 = 20 + 20 = 100
3 * 20 = 100 + 20 = 120

  __130__________
20 | 3211
   20______
   121
   120______
     11
     
quotient: 130
remainder: 11 (base 8 equivalent is 5)
     
  __3______________   
20 | 130
   120_____
    10 

quotient: 3
remainder: 10 (base 8 equivalent is 4)

  __0________
20 | 3

quotient: 0
remainder: 3

So in the end we are left with 345. So 3211 in base 4 has been converted to 345 in base 8.

Do note that when we did base 8 to base 4 conversion above, I didn't create multiplication table. That was because I didn't want to confuse you in the beginning. It was handled implicitly as we were converting to higher base & that base was less than 10. But we were actually doing  arithmetic in base 8 system. So whenever you are doing direct conversion from one number base to another, make sure you have created the proper multiplication table first.

Difference Between Voluntary And Involuntary Context Switches

So I assume that you know what context switching is. Suppose you are running an OS in a dual core processor. And at some point, your application is running four threads. Operating system kernel needs to divide the CPU time among them. You are running four threads in two cores after all. This is the job of process scheduler which runs as a function in kernel. When invoked, it will look into a queue & select next thread which will get CPU time. This switching between threads can happen in two ways.
A thread can give up control of CPU as it will generally wait on I/O, user input. Or it might be sleeping. So another thread can be selected to start running on the same CPU core. This is called voluntary context switch.
But sometimes the thread is doing some CPU intensive task & runs out of CPU time scheduled for it. Then process scheduler will take the thread out & add it back to the queue. It will then put next thread on the CPU. This is called involuntary context switch.
Hope this clarifies the difference in simple terms. I might write some more on involuntary context switches later.

Solve Google Chrome Sound Issue In Windows

Just last week I solved this problem. In my Windows 10 laptop sound was fine. I was able to hear people in video chat. Even Microsoft Edge which is built-in browser for Windows was also working fine. But I was not getting any sound from Google Chrome. There can be various issues. But if there is no sound only in Chrome, then just check the below steps.


What happened in my case was that Chrome sound settings got disabled in Volume Mixer. So you need to right click on speaker icon on the task bar & then open Volume Mixer from the menu. There you should check if Google Chrome volume button is muted or not.
 

Direct Conversion From Any Number Base To Another Base Explained

Let's consider that we need to convert a base 4 number to base 8 number. Base 4 digits: 0 1 2 3 Base 8 digits: 0 1 2 3 4 5 6 7 We should...