using Java to realize the reciprocal mechanism between decimal and binary decimal
This blog mainly describes the use of Java to achieve decimal and binary
First of all, the whole idea:Hex that contains decimals, we can first divide it into integers and decimal parts,Then the string comparison is made and the corresponding substitution is made.
Contains the binary decimal, the idea is similar, need to notice that the left integer is not enough four digits of the 0, the right is the same.
Import Java.math.BigDecimal
Public classbinary{ Public Static voidMain (string[] args) {//Print binary representation of N. intN = Integer.parseint (args[0]); intv = 1; while(v ) v=v; //Now V is the largest power of 2 intn = n;//Current Excess while(V > 0) { //Cast out the power of 2 in decreasing order. if(N ); } Else{System.out.print (1); n-=v;} V= V/2; } System.out.println (); }}Prints a
#include void chang2 (int);#define MAX 100int main (){int input;printf ("Please input a int_number:\n");scanf ("%d", input);printf ("The number ' s binary is:");Chang2 (input);return 0;}void chang2 (int x){int arry[max]={0};int top=0;while (x){Top+=1;arry[top]=x%2;X=X/2;}while (top!=0){printf ("%d", arry[top]);top--;}printf ("\ n");}This article is from the "7378168" blog, please be sure to keep this source http://7388168.blog.51cto.com/7378168/169672
implement various transformations in the Java language (binary, octal, decimal, hexadecimal, mainly using Java Swing technology)
1, the original question
Enter a hexadecimal number from the keyboard, convert it to a decimal number, and then output. If the input is not a val
of 60, it consumes 32 bits of space in memory. As shown below:0000-0000 0000-0000 0000-0000 0011-1100Hexadecimal values are represented by the 16 numbers 0~9 and A~f , which are rounded when 16 is satisfied. 60 is represented in hexadecimal in Java as: 0x3C, which behaves in memory as:The octal value is represented by the 8 number of 0~7, and is rounded when 8 is satisfied. 60 in Java, denoted by octal: 07
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
convert decimal number to binary in Java
The first one: except for the basis of the reverse method
This is the most consistent with our usual mathematical logical thinking, that is, enter a decimal number n, each time with n divided by 2, the remainder of the note down, and then use the quotient to remove the 2 ... Lo
) {System.out.print ("0");return; //Return here and end this method when the received data is 0.}while (num! = 0) {int x = num 15;ARR[--P] = chs[x]; //In the process of saving, starting from the highest bit. This is the first number to be calculated, and the last one to be stored in the array.num = num >>> 4; //Move num to the right by 4 2 binary bits. >>> code unsigned Right shift. >> represents a signed shift.}for (int i=p;iSystem.out.print (Arr
1 PackageCom.llh.demo;2 3 ImportJava.util.Scanner;4 5 /**6 * 7 * @authorLLH8 *9 */Ten Public classTest { One /* A * Convert any decimal number to binary form and output the converted result (using array storage) - */ - Public Static voidMain (string[] args) { theScanner sc =NewScanner (system.in); -System.out.println ("Please enter a decimal n
public class Decimaltonbigit {/** * decimal number (can be negative) to N (n between [2,36]) * @author wl */public static final int n=36;//n represents N binary public static void Main (string[] args) {int Data=71;//data represents the number of Tonbigit (data,n) to convert;} private static void Tonbigit (int data, int a) {if (a>36| | AOutput:1Z Java
Some small algorithms are of the Java version, and a large number of questions on the network are aimed at C ++. Therefore, Java implementation is rare, but they are the basis of the test,
The implementation is the same. You can broaden your thinking and be helpful.
/*** 1 hop steps* Question: there are N levels in a step. If you can skip 1 level at a time, you can also skip 2 levels.* Calculate the total
For example: 5 of the binary conversion method is 5 divided by 2 is the remainder 1 and then the quotient value 2 continues to divide by 2 the remainder 0 and then the quotient value is 1, so the last to get the binary value is 101Public static void Main (string[] args) {StringBuffer SBF = ToBin (ten);String Str=sbf.reverse (). toString ();System.out.println (str); }static StringBuffer toBin (int x) {str
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.