Decimal conversion to binary, octal, hexadecimal
From decimal to other binary conversions, the remainder is read by dividing the number by the number of binary numbers to be converted. Connected together on it.
Copy CodeThe code is as follows:
/**
* decimal-to-binary,
#!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每次从左插入计算后的
All types in Python exist as objects.There is no char type in Python, only a string type, which makes it very inconvenient for us to convert the char type to integer, but Python already provides built-in functions for these transformations.In Python, in addition to Integer, the other binary can only be represented by a string.1 int ()Binary, octal, 16-
printf is a formatted output function that can print directly decimal, octal, hexadecimal, output control characters%d,%o,%x, but it does not exist binary, if output binary, can be handwritten, But you can also call the Itoa function inside Stdlib.h, which is not a function in the standard library, but most compilers have this function, so let's introduceThe prot
Basic practice hex to octal time limit: 1.0s memory limit: 512.0MBThe 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 co
Basic practice hex to octal time limit: 1.0s memory limit: 512.0MBProblem DescriptionGiven n hexadecimal positive integers, output their corresponding octal numbers.Input FormatThe first behavior of the input is 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
CharNumh=H.charat (m); -String b=integer.tobinarystring (integer.valueof (string.valueof (NUMH), 16)); - - for(intK=b.length (); k){ +b= ' 0 ' +b; - } + A Tempb.append (b); at } - - /*Binary into octal*/ -StringBuilder tempo=NewStringBuilder ();//The length becomes a multiple of 3 and the number of leading 0
1292: Hex Turn octal
time limit: 1 Sec
memory limit: MB
Submissions: 1
Resolution: 1
Submitted State [Discussion Version] [Edit]
Title DescriptionGiven n hexadecimal positive integers, output their corresponding octal numbers.InputThe first behavior of the input is a positive integer n (1OutputOutputs n rows, each of which enters a corr
Basic Practice hex to octaltime limit: 1.0s memory limit: 512.0MBProblem Descriptiongiven n hexadecimal positive integers, output their corresponding octal numbers. Input Format The first behavior of the input is 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.
(' 111 '); Output 7Bindec(PHP 3, PHP 4, PHP 5)Bindec--Binary conversion to decimalDescriptionNumber Bindec (String binary_string)Returns the decimal value of the binary number represented by the binary_string parameter.Bindec () converts a binary number to an integer. The maximum number of convertible is 31 bits 1 or decimal 2147483647. Starting with PHP 4.1.0,
relationship, that is, 23=8,24=16, while octal and hex are used in this Derived from the relationship, that is, a three-bit binary representation of an octal, with a four-bit binary representation of a hexadecimal number. Next, remember 4 numbers 8, 4, 2, 1 (23=8, 22=4, 21=
.,111,111,111,111,11e,+32 binary value?11111111111111111111111111111001As above, the binary length is 32 bits, that is, the integer is a negative number, the first negation, get the inverse code:00000000000000000000000000000110Anti-code +1, get:00000000000000000000000000000111Convert to decimal: 7Because it is negative, add a minus sign, convert to 7Fun: What is a 32-bit
octal and hex are used in thisDerived from the relationship, that is, a three-bit binary representation of an octal, with a four-bit binary representation of a hexadecimal number.Next, remember 4 numbers 8, 4, 2, 1 (23=8, 22=4, 21=2, 20=1). Now let's practice the conversion
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 foll
the inverse code:
00000000000000000000000000000110
Counter code +1, get:
00000000000000000000000000000111
Convert to decimal: 7
Because it's a negative number, add a minus sign and convert to 7.
Fun: 32-bit binary 1.,111,111,111,111,11e,+31 What is the value of the binary?
This is a more interesting, do not mislead to this is a negative number, in fact, this is an integer, because there are only 31 di
the island, after all, someone else's Japanese level, if not to the heart also can't get through.Or as usual, eating a copy of the hand, discussing what we have been doing in the company recently, an unintentional conversation, he asked me to know what is binary, I said know, he went on to ask, do you know how to use it, I said don't know, don't use binary, still can't write code? Said so much after all, U
function can handle large values, in which case it returns a float type.three, octal (octal system) conversion function DescriptionOctal decimal octdec () functionEcho Octdec (' 77 '); Output 63Echo Octdec (DECOCT (45)); Output 45Octdec(PHP 3, PHP 4, PHP 5)Octdec--Eight binary to decimalDescriptionNumber Octdec (String octal_string)Returns the decimal equivalent
binary, need to be divided into integers and two parts of the fractional conversion2) When converting integers, the use of the addition of 2 to the remainder method, and the conversion of decimals, with the use of 2 rounding method3) Note the direction of their readingsso we can derive from the above method that the decimal number 168.125 is converted to binary 10101000.001, or the decimal number is conver
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.