Binary. Octal. Decimal. Hexadecimal conversion between

First, the conversion between decimal and binary (1) decimal to binary, is divided into an integer part and fractional part ① integral part of the way: In addition to taking over France 2, which will be integral parts of each divided by 2, for the remainder of Right the number, but to continue to divide by 2, the remainder a bit further to the right of the number, this step has been to continue until the business is 0 until the time the last reading, the remainder from the last time, has been to the top of the a remainder. The following are examples:
Example: 168 decimal to binary conversion

The outcome will be converted to binary decimal 168, (10101000) 2
Analysis: The first step would be 168 divided by 2, Business 84, the remainder is 0.
The second step will be 84 divided by 2 operators, commercial number 42 I 0.
The third step will be 42 divided by 2 operators, the number of operators more than 21 to 0.
The fourth step would be 21 divided by 2 operators, the number of business more than 10 to 1.
The fifth step, the business 10 divided by 2, Business 5 the remainder is 0.
The sixth step, the business 5 divided by 2, remainder is 1 business 2.
Seventh step, the Business 2 divided by 2, Business 1, the remainder is 0.
Step eight would be 1 divided by 2 operators, business 0 remainder of 1.
Ninth step of reading, because the last one is only obtained after repeated divided by 2, so it is the highest place, reading the remainder of the word forward from the last time, that is, 10101000

(2) fractional method: Take 2 to take the whole law, be the fractional part multiplied by 2, then take the integer part, the remaining fractional part of the continuing multiplied by 2, then take the integer part, then multiplied by the fractional part of the remaining 2 fractional part of zero has been taken to date. If you can never be zero, the decimal rounding with the same number of decimal places as required retention time, under the back of a is 0 or 1, choice, if it is zero, give it up, if it is 1, to enter one. In other words, 0 round 1 entry. Reading back from the front of the integer read integer, the following example:
Example 1: The conversion to binary 0.125

Outcome: to convert a binary 0.125 (0.001) 2
Analysis: The first step would be 0.125 multiplied by 2, was 0.25, the integer part is 0, the fractional part 0.25;
The second step, the fractional part of 0.25 multiplied by 2, 0.5, 0 is an integer part, fractional part is 0.5;
The third step, the fractional part will be multiplied by 2, 0.5, 1.0, then the integer part of 1, the fractional part of 0.0;
The fourth step, reading, starting from the first reading, read the last one, that is, 0.001.

Example 2, the 0.45 is converted to binary (reserved to the fourth decimal point)

We can see from the above steps, when the fifth time to do multiplication, and the result is 0.4, then multiplied by the fractional part to 2, was 0.8,0.8 then multiplied by 2, to 1.6 this has been by it and eventually impossible be the fractional part of zero, so this time had to learn the method of rounding decimal, but binary only 0 and 1, 2, and so it was round 1 into 0. This is also the computer will produce errors in the conversion, but because the median number of reservations, high precision, it can be ignored.
So, we can conclude that the results will be converted to a binary equivalent to about 0.45 0.0111
Described above is converted to decimal to binary approach, need to note that:
1) decimal to binary, to be divided into two parts respectively, integer and fractional conversion
2) When converting an integer, with the addition of more than 2 out of law and the conversion decimal time, using a rounding method by 2
3) Note the direction of their reading, therefore, we approach from above, we can draw a decimal number converted to binary as 10,101,000.001 168.125, or 168.45 is converted to a binary decimal number about equal to 10101000.0111.

(3) is converted to decimal, regardless of the binary integer and fractional method: the right to add according to law, be multiplied by the binary number of each on the right, then the sum of which is a decimal number. Example will convert a binary number to decimal number 101.101.

Outcome: (101.101) 2 = (5.625) 10
We are doing the binary into decimal to note that
1) The right to know the value of each binary
2) to be able to calculate the value of each (Note: the weight behind the decimal point is 2 (-1), 2 (-2), etc.).

Decimal octal and hexadecimal transfer of principles with the principle of transfer as binary.

分类:Tech 时间:2010-02-21 人气:468
blog comments powered by Disqus


  • To query data retention decimal places 2011-01-27

    select dep_name, sum (workload_full) workload_full, sum (workload_real) workload_real, cast ((sum (workload_real) / sum (workload_full)) as numeric (6,2)) as Workload_perc from jshx_person_workload_rate where reportid = 194326 group by dep_name To qu

  • in javascript how to get only two decimal places? 2009-08-16

    Cases sum = parseFloat (8.99) + parseFloat (7.50); Wait until the value is: 16.4900000002 How to get only two decimal places? <script language="JScript"> Number.prototype.toFixed = function (num) ( / / Re-structure toFixed method, IE5.0 +

  • to retain two decimal places java 2010-03-29

    to retain two decimal places java questions: Mode 1: Rounding double f = 111231.5585; BigDecimal b = new BigDecimal (f); double f1 = b.setScale (2, BigDecimal.ROUND_HALF_UP). doubleValue (); Mode 2: java.text.DecimalFormat df = new java.text.DecimalF

  • JS float type conversion and take n decimal places 2010-03-27

    javascript variables are weakly typed, all the variables are declared as var, the type conversion process there is no java so convenient, it is through parseInt (variable), parseFloat (variable) and other methods to carry out the type conversion. Not

  • actionscript how to control the number precision (decimal places) 2010-04-16

    Very simple thing, but if you do not know it as a hassle. Number two bag approach can easily solve, rather than the Math package. Here is the official document: toFixed (3) How to return rounded to three decimal places of the string. var num: Number

  • Javascript interception of decimal places and rounded 2010-05-05

    round method Role: to return and give expression to the nearest integer value. Syntax: Math.round (number), will be option number parameter is rounded to the nearest integer value. Note: If the number is greater than equal to the fractional part of 0

  • vc arbitrary bit string, said the figures rounded to the nearest decimal places to retain and 2010-06-03

    BOOL SHGlobal::isIntOrDecimal(CString strItem) { // Determine whether an integer or decimal // Returns 0 for not // Returns the integer 1 representative // Returns 2 represents decimal if(strItem.IsEmpty()) return FALSE; for(int i = 0; i <strItem.Get

  • js number of decimal places retained 2010-06-13

    javascript rounding decimal (n decimal places to retain rounded) 2009-05-12 15:44 javascript decimal rounding First, problems arise: Own coding, javascript encountered in 3.21 * 3 = 9.629999999999999 phenomenon Second, Baidu about

  • oracle decimal places and rounded to retain 2010-08-20

    Decimal places retained, it is noteworthy about Colleagues found recently changed the code so he wrote select to_char(round(123456789), rpad('999999', Dynamic reserved bits parameter ,'0')) from dual If the dynamic parameter is the 9 digit retained n

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 闽ICP备15018612号

processed in 0.044 (s). 12 q(s)