In my impression, it is a common problem to convert into one another, so in Python, the following code should be accepted as util.
This is a search from the Internet also can also be a Python binary conversion, verified can be used. The implementation code is posted below:
#!/usr/bin/env python #-*-coding:utf-8-*-# 2/10/16 base Trans. wrote by Srcdog on 20th, April, $ ld elements in Base 2, 10, 16. Import Os,sys # global definition # base = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F] base
C # conversion between decimal and binary, hexadecimal, and octal,
1. Convert decimal to binary
After dividing the decimal number by 2, you can enter all the remainder into two parts to obtain the required binary data.
Public static string DecimalToBinary (int vDecimal) {/* divide the decimal number vDecimal by 2, take the remainder * and enter the remainder in reverse order */List
2. Convert binary to decimal
Multiply the values (0 or 1) in binary
octal | binary | decimal | hexadecimal | Convert public Function d_to_b (ByVal Dec as Long) as String
Todo
D_to_b = Dec Mod 2 D_to_b
Dec = Dec \ 2
Loop while Dec
End Function
Public Function b_to_d (ByVal Bin as String) as Integer
Dim I as Long
For i = 1 to Len (Bin)
B_to_d = b_to_d * 2 + Val (Mid (Bin, I, 1))
Next I
End Function
Public Function H_to_b (ByVal Hex As String) as String
Dim I as Long
Dim B as String
Hex = UCase (Hex)
For i = 1 to Le
1. Binary The binary is a notation that can represent all values with a finite number symbol. is made up of specific values.2. The representation of the binary Binary: consists of 0 and 12 digits.Octal: Consists of 0-7 numbers, in order to differentiate it from the other binary numbers, beginning with 0.Decimal: All are made up of 0-9 of these nine digits and cannot start with 0.Hex: Consists of 0-9 and a-f. To differentiate between other numbers, start with 0x or 0X.3. Conversion between the
The shell can represent different data in the system without invoking the 3rd party command. The following presentation method is summarized here. The default value of the shell script is handled by the 10 number, unless the number has a special notation or prefix at the beginning. Can be used to represent other types of values in the system. For example: Starting with 0 is 8. The beginning of the 0x is the 16 number. Using Base#number this form can represent other systems. Base value: 2-64.
Ho
the three types of input that the C + + language itself supports are:1. Decimal. such as 56.2.16 binary, starting with 0x, such as 0x7a. Output hexadecimal hex keyword formatting, such as cout3. Eight binary, starting with 0, for example 030. The output octal is formatted with the OCT keyword, such as cout
The following sample program:
#include
The output results are:a=10B=8C=16A (octal) =12A (hexadeci
The Title Description converts the decimal number to octal and outputs the result. Figure: converts the decimal number to octal and outputs the input format. The input contains several decimal positive integers. Output the corresponding Octal numbers, each of which occupies one row. Sample input 1237891910020345 sample output 123710112346162771
# Include
One, test instructions:ask for an octal decimal in decimal. Two, ideas:Violent array simulation calculation, pay attention to do not take the decimal division operation1, for octal decimals, converted to decimal, written form analysis:2, simulate the division process:3, output. Three, step:1,0.756[8], ((6/8 + 5)/8 + 7)/8 [ten]2, Division process: such as 0.75I,5/8 Results if the whole number, then 5000/8=62
Recently knocked a question, is a conversion between the system, have to say this problem let me understand that the water must be water when the problem.16 first go to two, a hexadecimal number can be converted to a four-bit binary number, and then an octal number can be converted to a three-bit binary number, but, the baby naïve thought I need to constantly into the conversion, and finally found that can be made of two character array for the conver
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 prototype of the ITOA function is char* itoa (int value, char * string, int radix); int value
/**************************************************************************************** parameter one: converted 10 binary * Energy : decimal conversion to octal * return value: 0****************************************************************************************/int Fntentoeight (int nnum) {int ndig[11] = {0}; octal number of type int, up to 11-bit int i = 0;for (i = ten;
Write a function that converts a decimal number to its corresponding octal number. The program reads in a decimal number, calls the function to implement the number conversion, the output corresponding octal. Sample Input9274Sample Output22072Sample Input -Sample Output22Code one;#include #include using namespace Std;int main (){int n;CIN >> N;printf ("%o\n", N);return 0;}Code two: #include #include using
As we all know, the memory address space is represented by hexadecimal data, such as 0x8049324. Why do we need to represent it in hexadecimal format? What is the significance of the hexadecimal system?
In programming, we usually use 10 hexadecimal. After all, C/C ++ is a high-level language.
For example, int A = 100, B = 99;
However, because the representation of data in a computer exists in binary format, sometimes binary can be used to solve the problem more intuitively. However, the
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.