Base 8 to hexadecimal conversion - hex

I would just like to confirm the following answer.
7037108.
8 does not form part of the number. Converting this to hexadecimal I get the answer ABCDE. Is this correct? If so what is the purpose of the subscript / base 8 which is written slightly below the number 703710.

A very simple way of converting octal to hex is through binary: octal digits correspond to three binary digits, while hex digits correspond to four. Convert the number to binary, regroup by four-bit nibbles, and then convert to hex.
The number converted to binary looks like this:
111 000 011 111 001 000
7 0 3 7 1 0
Regroup by nibbles and add leading zeros for conversion to hex:
0011 1000 0111 1100 1000
Now you can easily convert the number using a lookup table.

The subscript indicates what base the number is already written in, in this case 8, so it's octal.
So 7037108 is saying that the number is 7 * 8^5 + 0 * 8^4 + 3 * 8^3 + 7 * 8^2 + 1 * 8^1 + 0 * 8^0, or 231368 in base 10.
IOW, 7037108 = 23136810 = 387C816.
ABCDE (by which you mean ABCDE16, or 0xABCDE), would be the right answer if the original number were written in base 10, because 70371010 = ABCDE16.

Related

Converting decimal with comma to binary

I'm trying to convert decimal numbers with commas into binary. I've seen that if you have for example the number 5.2 in decimal you convert it to 101.10, since 5 is 101 and 2 is 10 but I've seen a method that I don't quite understand.
For example, the number 93.3125 is 0000 0101 1101 0101. Why ?
Are there other methods that help you transform decimals with comma into binary ?
You need to handle each part (before and after decimal point) separately. The integer part is converted by consequent division by base and the decimal part by consequent multiplying by base. In your case base = 2:
5.2 dec -> 5 + 0.2 dec
Integer part
5 % 2 = 1 // binary digit
5 / 2 = 2 // leftover for next iteration
2 % 2 = 0 // binary digit
2 / 2 = 1 // leftover for next iteration
1 % 2 = 1 // binary digit
1 / 2 = 0 // leftover for next iteration
Do not forget that the digits has to be used in reverse order (your 5 is the same however):
5 dec = 1 0 1 bin
Decimal part
0.2 * 2 = 0.4
0.4 * 2 = 0.8
0.8 * 2 = 1.6
0.6 * 2 = 1.2
0.2 * 2 = 0.4
...
All is in decadic. The integer part of result is your digit (in order) and the decimal part is leftover for next iteration. So the result is:
0.2 dec = 0 . 0 0 1 1 0 ... bin
Putting together:
5.2 dec = 101.00110... bin
There are a multitude of ways to convert a decimal number into a string of 1s and 0s. You have just demonstrated two of them.
If you convert the number (represented in base-10 place notation) 93.3125 into "binary" (represented in base-2 place notation) you get 1011101.0101
If you convert it into a a binary floating-point format used in a computer language, you get a string of 1s and 0s, perhaps with a leading bit indicating sign, and some other bits for exponent -- you'll need a format description document to decode it.
Translating "5.2" into "101.10" (translating the parts before and after the decimal point separately) is a new one on me, and it is not a mathematically correct translation of place notation. "5"=>"101" is correct, but ".2"=>".10" is not; ".2" in decimal is two tenths, a.k.a. one fifth, which in base two is ".001100110011..." (one fifth is a repeating decimal in base two, just as one third is a repeating decimal in base ten.) And how would you translate "1.02"?
So yes, there are plenty of ways to encode a number in binary. Different codes are useful in different ways.

Convert binary, octal, hexa FLOATS to decimal "manually" (ex: [135.263]B10 -> [?]B2)

I'm a student in programmation and I have a course called "Informatic Mathematics". In the exercices it's asked to convert floating numbers from decimal, octal, hexadecimal or binary to another base (not necesserly to base 10) and keep 12 digits after the comma(or the dot) if it is possible. For exemple:
(135.263)b10 => b2
(100101001.11)b2 => b10
(1011110010.0101)b2 => b8
...
I know how to convert numbers. The way I convert the decimal part (after the dot) is to divide this part by the highest multiple of the target base until I get 0 or until I reach the 12th digits after the dot. The problem is that I don't know all the negate multiples of 2 so usually I write them on a separate sheet, but usually I don't have to keep 12 digits after the dot and writing these multiples on a seperate sheet takes time and during the exam, time is a precious thing and I can't waste it to write these multiples.
So I would like to know if there's a better way to do these conversions or if anyone has any tips.
Also, when I convert from non-decimal number to another non-decimal number (ex: b2 => b8) I usually convert the first number to base 10 and then convert the base 10 number to the target base. I would like to know if there's a way to convert the first number directly into the target base without having to convert it in base 10 first.
BTW: Sorry if my english is a bit weird. I'm a french canadian and I did my best, but please let me know if there is something you do not understand well.
I'll start with b2 > b8.
001 011 110 010.010 100
As you see, I've separated the number into 3 digit segments (2^3 = 8). You have to add extra 0 to the left and to the right to make it like that. Then you convert it digit by digit. In this case you'll receive 1352.24
b2 => b10
Some harder math here. Mark digits in your number this way:
1 0 0 1 0 1 0 0 1 . 1 1
8 7 6 5 4 3 2 1 0 -1 -2
Then calculate fractional and whole part
2^0 + 2^3 + 2^5 + 2^8 + 2^-1 + 2^-2
b10 => b2
Multiple the fraction by 2 till you get 1. From each multiplication you take the whole part. Example:
0.25 * 2 = 0.5; 0.5 * 2 = 1;
Thus, 0.25 is 0.01;
UPD For negative conversions check out first and second complement.

Decimal value from bit group in word math explanation

11111 111111 11111 > 16 bit
R G B
how can I get the R/G/B values?
R = x/2048 (2048 are the 6+5 G+B 11 bit)
G = x-R*2048/32 (32 are the B )
is there a simple explanation of this? why should the decimal value be divided by others bit to get the single group value?
If you want to get R you have to move 11 bits on the right so that G and B disappear. So
R=x>>11
but every shift of 1 bit is equivalent to a division by 2 so the expression above is equivalent to
R=X/(2^11)=x/2048
And so you get the R.
To get the G, according to the formula, you can first remove the R, which is the R you obtained previously but shift back of 11 bits (or multiplied by 2048). Now done this you have a number like:
111111 11111
You shift left of 5 bits (or divide for 32) and you get the result.
Note that in practice you can do this easier doing this:
B=(x and 0x1F)
G=((x>>5) and 0x3F)
R=((x>>11) and 0x1F)

How to convert decimal to hexadecimal using brain?

Since I knew how to manually convert hexadecimal to decimal using this method.
Read from right to left, the last digit multiplied by the constant value 16 and plus the first digit.
For example:
12h = 2 + (1 * 16) = 18
99h = 9 + (9 * 16) = 153
How do I convert back into hex from decimal?
As you can see in the picture above. You need to draw a table in your brain
Lets take 456 as example.
If we divide 456 by 16 . Remainder = 8 & Quotient = 28
We further divide 28 by 16 and get remainder = 12 & quotient = 1
Now further dividing 1 by 16 results in remainder = 1 and quotient = 0
So we stop.
Now we take the remainders, bottom up.
1 , 12 , 8
Converting 12 in hex notation gives C.
So the answer is 1C8
To convert from decimal to hex you must know the powers of 16. 16^1 is obviously 16; 16^2 is 256; 16^3 is 4096; 16^4 is 65536; etc.
For each power of 16, divide the number by that power to get one hex digit. Then take the remainder and divide by the next lower power of 16.
This is enough of a hassle that it's easiest to let a calculator do it, or use a scripting language such as Python.

What is a canonical signed digit?

What is a canonical signed digit (CSD) and how does one convert a binary number to a CSD and a CSD back to a binary number? How do you know if a digit of a CSD should be canonically chosen to be +, -, or 0?
Signed-digit binary uses three symbols in each power-of-two position: -1, 0, 1. The value represented is the sum of the positional coefficients times the corresponding power of 2, just like binary, the difference being that some of the coefficients may be -1. A number can have multiple distinct representations in this system.
Canonical signed digit representation is the same, but subject to the constraint that no two consecutive digits are non-0. It works out that each number has a unique representation in CSD.
See slides 31 onwards in Parhi's Bit Level Arithmetic for more, including a binary to CSD conversion algorithm.
What is canonical signed digit format?
Canonical Signed Digit (CSD) is a type of number representation. The important characteristics of the CSD presentation are:
CSD presentation of a number consists of numbers 0, 1 and -1. [1, 2].
The CSD presentation of a number is unique [2].
The number of nonzero digits is minimal [2].
There cannot be two consecutive non-zero digits [2].
How to convert a number into its CSD presentation?
First, find the binary presentation of the number.
Example 1
Lets take for example a number 287, which is 1 0001 1111 in binary representation. (256 + 16 + 8 + 4 + 2 + 1 = 287)
1 0001 1111
Starting from the right (LSB), if you find more than non-zero elements (1 or -1) in a row, take all of them, plus the next zero. (if there is not zero at the left side of the MSB, create one there). We see that the first part of this number is
01 1111
Add 1 to the number (i.e. change the 0 to 1, and all the 1's to 0's), and force the rightmost digit to be -1.
01 1111 -> 10 000-1
You can check that the number is still the same: 16 + 8 + 4 + 2 + 1 = 31 = 32 + (-1).
Now the number looks like this
1 0010 000-1
Since there are no more consecutive non-zero digits, the conversion is complete. Thus, the CSD presentation for the number 287 is 1 0010 000-1, which is 256 + 31 - 1.
Example 2
How about a little more challenging example. Number 345. In binary, it is
1 0101 1001
Find the first place (starting from righ), where there are more than one non-zero numbers in a row. Take also the next zero. Add one to it, and force the rightmost digit to be -1.
1 0110 -1001
Now we just created another pair of ones, which has to be transformed. Take the 011, and add one to it (get 100), and force the last digit to be -1. (get 10-1). Now the number looks like this
1 10-10 -1001
Do the same thing again. This time, you will have to imagine a zero in the left side of the MSB.
10 -10-10 -1001
You can make sure that this is the right CSD presentation by observing that: 1) There are no consecutive non-zero digits. 2) The sum adds to 325 (512 - 128 - 32 - 8 + 1 = 345).
More formal definitions of this algorithm can be found in [2].
Motivation behind the CSD presentation
CSD might be used in some other applications, too, but this is the digital microelectronics perspective. It is often used in digital multiplication. [1, 2]. Digital multiplication consists of two phases: Computing partial products and summing up the partial product. Let's consider the multiplication of 1010 and 1011:
1010
x 1011
1010
1010
0000
+ 1010
= 1101110
As we can see, the number of non-zero partial products (the 1010's), which are has to be summed up depends on the number of non-zero digits in the multiplier. Thus, the computation time of the sum of the partial products depends on the number of non-zero digits in the multiplier. Therefore the digital multiplication using CSD converted numbers is faster than using conventional digital numbers. The CSD form contains 33% less non-zero digits than the binary presentation (on average). For example, a conventional double precision floating point multiplication might take 100.2 ns, but only 93.2 ns, when using the CSD presentation. [1]
And how about the negative ones, then. Are there actually three states (voltage levels) in the microcircuit? No, the partial products calculated with the negative sign are not summed right away. Instead, you add the 2's complement (i.e. the negative presentation) of these numbers to the final sum.
Sources:
[1] D. Harini Sharma, Addanki
Purna Ramesh: Floating point multiplier using Canonical Signed
Digit
[2] Gustavo A. Ruiz, Mercedes Grand: Efficient canonic signed digit recoding

Resources