Conversion of various basic types in python, binary, octal, decimal, and hexadecimal
All types in python exist as objects.
In python, there is no char type and only a string type. This may be inconvenient to convert the char type to an integer type, but python already provides these built-in functions for conversion.
In python, except integer types, other hexadecimal types can only be represented by strings.
1 int ()
Convert binary,
Octal FractionsAbstract: Convert octal decimals to decimal small trees. The number of decimals is very large.You can use Bigdeciaml seconds in Java to drop. Time:297ms1 Importjava.math.*;2 ImportJava.util.*;3 ImportJava.io.*;4 Importjava.text.*;5 6 Public classMain7 {8 Static intms=3005;9 Public Static voidMain (string[] args)Ten { OneScanner cin=NewScanner (NewBuffe
The first part of the Chinese character encoding Study Series. the PHP function is a detailed description of the conversion functions for decimal, binary, octal, and hexadecimal conversion. it mainly describes the conversion methods for each hexadecimal conversion to be used in actual development.
1. description of the decimal system conversion function1. decimal to binary decbin () function, as shown in the following example:
Echo decbin (12); // ou
In C ++, is 0 decimal or octal? Even in any number of input systems, 0 has only one value, that is, "zero". The reason for asking this question is purely idle. He recently discussed the topic about data with his friends. He said that eight-digit data has almost never been used. I cannot refute it for a moment. Indeed, apart from the commonly used decimal system, binary and hexadecimal are the most used in the computer, and the
Even in any number of input systems, 0 has only one value, that is, "zero". The reason for asking this question is purely idle.
He recently discussed the topic about data with his friends. He said that eight-digit data has almost never been used. I can't refute it for a moment. Indeed, apart from the commonly used decimal system, binary and hexadecimal are the most used in the computer, and the octal number is really "niche ".
When I got home, I tho
The problem describes the given n hexadecimal positive integers, outputting their corresponding octal numbers. Enter the first behavior of the input format as a positive integer n (1Next n rows, each line a string of 0~9, uppercase letters A~F, representing the hexadecimal positive integer to be converted, each hexadecimal number is not more than 100000. The output format outputs n rows, and each behavior enters a corresponding
Link: http://poj.grids.cn/practice/2765/
Question:
Total time limit:
1000 ms
Memory limit:
65536kB
Description
Decimal decimal places can be exactly expressed. For example, 0.75 in octal equals 0.963125 in decimal format (7/8 + 5/64 ). All octal decimal places with n digits after the decimal point can be expressed as decimal places with no more
This article introduces in detail the application of decimal, binary, octal and 16 binary conversion functions in PHP, and the friends who need it can refer to the following.
One, decimal system conversion function description1, decimal to Binary decbin () function, the following example
The code is as follows
Copy Code
Echo Decbin (12); Output 1100Echo Decbin (26); Output 11010Decbin
(PHP 3, PHP 4, PHP 5)Decbin--d
Original PHP: binary, octal, hexadecimal, and mutual computing
In the previous chapter, binary, octal, hexadecimal, and reciprocal calculation are one,
This article focuses on the mutual calculation between binary, octal, and hexadecimal, and how to convert the binary into decimal.
How can we convert decimal to binary, octal
One, decimal system conversion function description1, decimal to Binary decbin () function, the following example
Echo Decbin (12); Output 1100
Echo Decbin (26); Output 11010
Decbin
(PHP 3, PHP 4, PHP 5)
Decbin--decimal conversion into binary
Description
string Decbin (int number)
Returns a string that contains a binary representation of the given number parameter. The maximum value that can be converted is a decimal of 4294967295, and the result is a string of 32 1.
2, decimal turn
/**
* decimal-to-binary, octal, hex-less digits 0 *
*
* @param array $datalist incoming data array (100,123,130)
* The binary @param int $bin conversion can be: 2,8,16
* @return Array return data array () returns no data conversion format
* @copyright Chengmo qq:8292669
*/
function Decto_bin ($datalist, $bin)
{
Static $arr =array (0,1,2,3,4,5,6,7,8,9, ' A ', ' B ', ' C ', ' d ', ' e ', ' f ');
if (!is_array ($datalist)) $datalist =array ($d
One or two binary number converted to decimal number The basic practice of converting a binary number to a decimal number is to first write the binary number as the weighted coefficient expansion, and then sum it by the decimal addition rule. This practice is known as the "weighted addition" method. Function to convert binary to decimalint binary_decimal (int num) {int dec = 0, base = 1, REM;while (num > 0) {rem = num% 10;Dec = Dec + rem*base;base = base*2;Num/= 10; } return Dec; Second, decimal
Title DescriptionThe 1234 output of the decimalOutputs the octal 1234 corresponding to its decimal numberOutputs the hexadecimal 1234 corresponding to its decimal numberInputNoOutput1234d=1234d1234o=668d1234h=4660dSample output1234d=1234d1234o=668d1234h=4660dTipsOutput the second line of "1234o=668d", 1234 is the capital letter O, not the number 0The code is as follows:#include Operation Result:OJ "decimal, octal
Decimal to binary, in addition to 2 OperationsDecimal 6 to binary is (note from right to left to write, use a formula from bottom to top)Binary to decimal, multiply by 2 procedureBinary decimal 0*2 1 - Time Square of 0 Square +1*2 +1*2 's 2 - Time Square =6Correspondence relationship0 1 0 1 0 132 16 8 4 2 1Add up the number of 1 corresponding positions, so it's One byte 1 1 1 1 1 1 1 1 The maximum value is 255Addition Operation 5 + 4=9, turning into binary operation1 0 1+1 0 01 0 0 1Othe
#!usr/bin/env python# Coding:utf-8def binary ():"Binary Method and algorithm"Number = TenNumber1 =Number2 =Print Bin (number), type (Bin (Number1)), Bin (Number2)#用十进制算法来表示二进制# except congruential: 10%2=0 put the string bit ' 0 ', 5%2=1 into the string 10 bits ' 10 ', 2%2=0 put in the Hundred ' 010 ', the last remainder into thousands ' 1010 'L = []While number>0:L.insert (0,str (number%2)) #临时列表l每次从左插入计算后的余数Number /= 2 #每次把Number除法的结果返回判断循环Print Ls = '. Join (l) #列表转换字符串循环Print Sdef octonary ()
In Python, different hexadecimal conversion (binary, octal, decimal, and hexadecimal) and python hexadecimal
In my opinion, hexadecimal conversion is indeed a common problem. Therefore, in Python, the following code is also indispensable.
This is an article from the Internet that can also be converted to Python, and can be used after verification. The following is the implementation code:
#! /Usr/bin/env python #-*-coding: UTF-8-*-#2/10/16 base trans.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.