HELP! I don't know binary, hexadecimal, octal and bit wise

I had not studied this before in the programming class, but now I need to know this. What are some good resources for learning these numbers and how to convert them? I'm pretty much going to remember them as a table of times.

+4
source share
7 answers

In our daily decimal system, the base number or radix is 10 . The radius of the numbering system tells us how many different digits are used. In the decimal system, we use the digits 0 through 9 .

The digit value is radix ^ i , where i is the calculation of the digital position on the right, starting from zero.

Decimal number 6789 broken:

  6 7 8 9 radix ^ i | | | | -------------- | | | +-- ones 10 ^ 0 = 1 | | +----- tens 10 ^ 1 = 10 | +-------- hundreds 10 ^ 2 = 100 +----------- thousands 10 ^ 3 = 1000 ones tens hundreds thousands ----------------------------------------------- (9 * 1) + (8 * 10) + (7 * 100) + (6 * 1000) = 9 + 80 + 700 + 6000 = 6789 

This chart will help us understand any number system in terms of decimal numbers.


The hexadecimal system radius is 16 , so we need to use the extra digits A...F to indicate 10...15 . Let us add the hexadecimal number of CDEFh same way:

  CDEF radix ^ i | | | | -------------- | | | +-- ones 16 ^ 0 = 1 | | +----- sixteens 16 ^ 1 = 16 | +-------- 256:s 16 ^ 2 = 256 +----------- 4096:s 16 ^ 3 = 4096 ones sixteens 256:s 4096:s ----------------------------------------------- (Fh * 1) + (Eh * 16) + (Dh * 256) + (Ch * 4096) = (15 * 1) + (14 * 16) + (13 * 256) + (12 * 4096) = 15 + 224 + 3328 + 49152 = 52719 

We just converted the number of CDEFh to a decimal number (i.e. changed base 16 to base 10 ).


In the binary system, radix 2 , so only the numbers 0 and 1 . Here is the conversion of the binary number 1010b to decimal:

  1 0 1 0 radix ^ i | | | | -------------- | | | +-- ones 2 ^ 0 = 1 | | +----- twos 2 ^ 1 = 2 | +-------- fours 2 ^ 2 = 4 +----------- eights 2 ^ 3 = 8 ones twos fours eights ----------------------------------------------- (0 * 1) + (1 * 2) + (0 * 4) + (1 * 8) = 0 + 2 + 0 + 8 = 10 

The octal system is the same, radix 8 , numbers 0...7 are used. Converting octal 04567 to decimal:

  4 5 6 7 radix ^ i | | | | -------------- | | | +-- ones 8 ^ 0 = 1 | | +----- eights 8 ^ 1 = 8 | +-------- 64:s 8 ^ 2 = 64 +----------- 512:s 8 ^ 3 = 512 ones eights 64:s 512:s ----------------------------------------------- (7 * 1) + (6 * 8) + (5 * 64) + (4 * 512) = 7 + 48 + 320 + 2048 = 2423 

So, to convert between number systems, you just need to change radix .

To learn about bitwise operators, see http://www.eskimo.com/~scs/cclass/int/sx4ab.html .

+16
source

This: http://members.tripod.com/numeric_systems/ seems like a good start.
By the way, there is information about it everywhere, you just need to look for it.

+2
source

Use Google:

 http://www.google.com/search?q=0b11110000+to+hex http://www.google.com/search?q=0b11110000+to+decimal http://www.google.com/search?q=0b11110000+to+octal http://www.google.com/search?q=4232+to+binary http://www.google.com/search?q=4232+to+hex http://www.google.com/search?q=4232+to+octal http://www.google.com/search?q=0xaf0e23+to+decimal http://www.google.com/search?q=0xaf0e23+to+binary http://www.google.com/search?q=0xaf0e23+to+octal 

The fundamental concept of numerical systems is the following: a number is the sum of each of its digits, multiplied by its base, raised to the point of position of the number.

Hex, decimal, octal and binary are all the "bases" of number systems, but they do the same thing. You already know the decimal place, so the easiest way to explain:

 4232 = 4 * 10^3 + 2 * 10^2 + 3 * 10^1 + 2 * 10^0 3210 <- the base that you raise each of the above digits to 

This exact principle applies to every base system.

Binary:

 0b11110000 = 1 * 2^7 + 1 * 2^6 + 1 * 2^5 + 1 * 2^4 + 0 * 2^3 + 0 * 2^2 + 0 * 2^1 + 0 * 2^0 76543210 <- the base that you raise each of the above digits to 

Hexadecimal (Hexadecimal):

 0xaf0e23 = 10 * 16^5 + 15 * 16^4 + 0 * 16^3 + 14 * 16^2 + 2 * 16^1 + 3 * 16^0 543210 <- the base that you raise each of the above digits to 

Hex is indeed the only common base that is not intuitively obvious because it uses alpha characters to describe the values ​​10,11,12,13,14 and 15, using the letters a, b, c, d, e and f, respectively.

We use binary, octal, and hexadecimal, because binary is a computer language (remember that a digital wire may or may not have current (values ​​1 or 0). Each hexadecimal character accurately describes four binary digits, and an octal character - 3 binary digits. Hex is used much more often than octal.

 0b0000 = 0x0 = 0 0b0001 = 0x1 = 1 0b0010 = 0x2 = 2 0b0011 = 0x3 = 3 0b0100 = 0x4 = 4 0b0101 = 0x5 = 5 0b0110 = 0x6 = 6 0b0111 = 0x7 = 7(this is as far as octal goes) 0b1000 = 0x8 = 8 0b1001 = 0x9 = 9 0b1010 = 0xa = 10 0b1011 = 0xb = 11 0b1100 = 0xc = 12 0b1101 = 0xd = 13 0b1110 = 0xe = 14 0b1111 = 0xf = 15 

The capitalization of hexadecimal numbers does not matter. The most important thing you should remember in terms of number systems is the table above. You should usually use Google when converting long hexadecimal or binary numbers to decimal numbers, but if you know the table above, you won’t need Google for many short strings.

As an exercise, I also recommend writing conversion methods in your chosen language to convert from one base system to another. They are simple iterators and will help reinforce ideas in your head. I like to write them like this: decimal_ot_binary(binarynum) instead of binary_to_decimal(binarynum) . Then you can nest them with the feeling: int x = decimal_ot_hex(hex_ot_binary(binary_ot_decimal(40001)));

Now that you see the hexadecimal number in the form 0x????? , you will find out that this is just a representation for a string of binary digits. Just convert each character in hexadecimal to the corresponding binary digit as above.

+2
source

Converting between binary, octal and hexadecimal is quite simple.

 binary <=> octal: three binary digits <=> one octal digit binary <=> hex: four binary digits <=> one hex digit octal <=> hex: four octal digits <=> three hex digits (by way of binary, if necessary) 

This is easy because the radixes for binary, octal and hexadecimal types are all degrees 2. The trick is between decimal and third, because 10 (the radius of the decimal) has this annoying factor of 5.

A few other answers show how to convert from binary, octal, and hexadecimal to decimal. The algorithm that I was taught to switch from decimal to another is to constantly divide by radius and read the remainders, as an answer going from right to left. For example, here's how to express 227 in hex:

  nn / 16 remainder --- ------ --------- 227 14 3 14 0 14 (=E) 

therefore the answer is E3.

+1
source

Learning how to convert number bases (also known as radixes) is a lot easier with the radix conversion tool, which does all the hard work for you.

Thus, you can quickly learn by converting a bunch of numbers to and from different rexics, and you will immediately see the result of the conversion.

Use this radix converter - http://www.sooeet.com/math/base-converter.php

to convert a list of decimal numbers to binary, octal, and hexadecimal (one number at a time).

Below are two lists of decimal numbers:

1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536

0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535

The two lists look the same, but when they are converted to binary, octal and hexadecimal, very different results are produced. Try and see.

To use this basic converter, enter a number or copy and paste any number from the above lists into the "Base-10" field and press Enter or Return on your keyboard. The number you enter is converted to binary (base-2), octal (base-8) and hexadecimal (base-16), as well as many other base numbers (radixes) from base-2 and base-36.

If you want to better understand radix conversion, read the tooltips next to each radix block to learn about the internal functions of each frame.

Now try changing the binary, octal, and hexadecimal numbers you got from converting the above lists, replacing binary, octal, or hexadecimal digits.

For example: Decimal 15 = binary 1111

Now, in the binary result (1111), replace any of the 1 binary digits (bits) with zero (0) and press Enter or Return on the keyboard.

In this example: Binary 1101 = decimal 13

You can see that the second bit on the right in the binary number has a weight of 2 decimal numbers.

Continue experimenting this way with decimal, binary, octal, and hexadecimal number conversions, and you will soon learn the topic.

+1
source

Here is my Python code for Numeral conversions (2,8,10,16) from any to any. it can help you.

 class Conversion: def __init__(self): pass def dec_to_any(self, data, base): return base(data) def any_to_dec(self, data, base): return int(data, base) def main(): menu ={1: 'dec to bin', 2:'dec to oct', 3:'dec to hex', 4: 'bin to dec', 5: 'bin to oct', 6:'bin to hex', 7: 'oct to bin', 8: 'oct to dec', 9: 'oct to hex', 10: 'hex to bin', 11: 'hex to oct', 12: 'hex to dec'} target_base = {'bin': bin,'oct': oct, 'hex': hex} src_base = {'bin': 2,'oct': 8, 'hex': 16} choice=int(input(str(menu)+"\nEnter your choice: ")) src, target = menu[choice].split()[0], menu[choice].split()[2] c=Conversion() val =input("Enter the value :") if(src == "dec"): val =int(val) value= c.dec_to_any(val, target_base[target]) print('Value is :', value) elif(target == "dec"): value = c.any_to_dec(val, src_base[src]) print('Value is :', value) else: val = c.any_to_dec(val, src_base[src]) value= c.dec_to_any(val, target_base[target]) print('Value is :', value) if __name__ == '__main__': main() 
+1
source

Decimal, Hexadecimal, Octal, Binary, and Multi Radical Converters

Perhaps playing with this built-in snippet might help ...

This small javascript fragment can be converted in all ways:

You can enter any valid entry in one of the input fields, they will be instantly converted to each other's fields.

Enter sample 10 or 100 , sequentially in each of the fields below (or try entering 1767707668033969 in an integer field;) ...

 function doChange(ent) { var val=ent.target.value; if (ent.target.id == 'hex') val=parseInt(val, 16); else if (ent.target.id == 'oct') val=parseInt(val, 8); else if (ent.target.id == 'bin') val=parseInt(val, 2); else if (ent.target.id == 'sel') val=parseInt(val, document.getElementById('radix').value); document.getElementById('int').value=(val*1).toString(10); document.getElementById('hex').value=(val*1).toString(16).toUpperCase(); document.getElementById('oct').value=(val*1).toString( 8); document.getElementById('bin').value=(val*1).toString( 2); document.getElementById('sel').value=(val*1).toString( document.getElementById('radix').value).toUpperCase(); } function selRadix(ent) { var radix=ent.target.value; document.getElementById('sel').value= (1*document.getElementById('int').value). toString(radix).toUpperCase(); } function wStart() { var ent=document.getElementsByTagName('input'); for (var i=0;i<ent.length;i++) { ent[i].addEventListener('keyup',doChange); ent[i].addEventListener('change',doChange); }; ent=document.getElementById('radix'); for (i=2;i<36;i++) ent.innerHTML+="<option>"+i+"</option>"; ent.innerHTML+='<option selected="true">36</option>'; ent.addEventListener('change',selRadix); } setTimeout(wStart,300); 
 body { font-family: sans; font-size: .8em; margin: 0pt; padding:1% } input#int { width: 12%; } input#hex { width: 10%; } input#oct { width: 18%; } input#bin, input#sel { width: 32%; } 
 <div> Int<input id="int"></input> Hex<input id="hex"></input> Oct<input id="oct"></input> Bin<input id="bin"></input> <hr /> Radix: <select id="radix"></select> <input id="sel"></input> </div> 
0
source

Source: https://habr.com/ru/post/1338199/


All Articles