Numerical Bases
Since we were kids, we have all used decimals to express quantities. This nomenclature that seems so logical to us may not seem so to an inhabitant of Classical Rome. For them, each symbol that they wrote to express a number always represented the same value:
I 1
II 2
III 3
IV 4
V 5
All the
I signs always represents the value 1 (one) wherever they are placed, and the
V sign always represents a value of 5 (five). Nevertheless that does not take place in our decimal system. When we write the decimal symbol 1 we are not always talking about a value of one (I in Roman numbers). For example:
1 I
10 X
100 C
In these cases, our symbol 1 does not have always a value of one (or I in Roman numbers). For example, in the second case, the symbol 1 represents a value of ten (or X in Roman) and in the third one, 1 represents a value of one hundred (or C).
For example:
275 is not equivalent to 2+7+5, it could rather be decomposed as 200+70+5:
200
+ 70
5
---
275
therefore, the first "2" sign is equivalent to 200 (2 x 100), the second "7" sign is equivalent to 70 (7 x 10) whereas the last sign corresponds to the value 5 (5 x 1).
This is because our system is a positional numeral system. Therefor the value of a given digit depends on its position within the entire number being represented. All the above can be mathematically represented in a very simple way. For example, to represent
the value 182736 we can assume that each digit is the product of itself multiplied by 10 powered to its place as exponent, beginning from the right with 10
0, following with 10
1, 10
2, and so on:
Octal numbers (base 8)
Like our "normal" numbers are
base 10 (or radix 10) because we have 10 different digits (from the 0 to the 9):
0123456789
the octals numbers include only the representations for the values from 0 to 7:
01234567
and, therefore, its mathematical base is 8. In C++ octal numbers are denoted by beginning always with a
0 digit. Let's see how we would write the first numbers in octal:
octal decimal
----- -------
0 0 (zero)
01 1 (one)
02 2 (two)
03 3 (three)
04 4 (four)
05 5 (five)
06 6 (six)
07 7 (seven)
010 8 (eight)
011 9 (nine)
012 10 (ten)
013 11 (eleven)
014 12 (twelve)
015 13 (thirteen)
016 14 (fourteen)
017 15 (fifteen)
020 16 (sixteen)
021 17 (seventeen)
Thus, for example, the number 17 (seventeen, or XVII in Roman) it is expressed
021 as an octal number in C++. We can apply the same mechanism that we saw previously for decimal numbers to the octal numbers simply by considering that its base is 8. For example, taking the octal number
071263:
therefore the octal number
071263 is expressed as 29363 in decimal numbers.
Hexadecimal numbers (base 16)
Like decimal numbers have 10 different digits to be represented (0123456789) and octal numbers have 8 (01234567), hexadecimal numbers have 16 different digits, that are represented by the numbers from 0 to 9 and the letters A, B, C, D, E and F, which together
serve us to represent the 16 different symbols that we need to express base 16 numbers:
hexadecimal decimal
----------- -------
0 0 (zero)
0x1 1 (one)
0x2 2 (two)
0x3 3 (three)
0x4 4 (four)
0x5 5 (five)
0x6 6 (six)
0x7 7 (seven)
0x8 8 (eight)
0x9 9 (nine)
0xA 10 (ten)
0xB 11 (eleven)
0xC 12 (twelve)
0xD 13 (thirteen)
0xE 14 (fourteen)
0xF 15 (fifteen)
0x10 16 (sixteen)
0x11 17 (seventeen)
In C++, hexadecimal numbers are preceded by
0x (zero, x).
Once again we can use the same method to translate a number from a base to another one:
Binary representations
Octal and hexadecimal numbers have a considerable advantage over our decimal numbers in the world of bits, and is that their bases (8 and 16) are perfect multiples of 2 (2
3 and 2
4, respectively), which allows us to make easier conversions
from these bases to binary than from decimal numbers (whose base is 2x5). For example, suppose that we want to translate the following binary sequence to numbers of other bases:
110011111010010100
In order to translate it to decimal we would need to conduct a mathematical operation similar to the one we have used previously to convert from hexadecimal or octal, which would give us the decimal number 212628.
Nevertheless to pass this sequence to octal it will only take us some seconds and even the less skilled in mathematics can do it just by seeing it: Since 8 is 2
3, we will separate the binary value in groups of 3 numbers:
110 011 111 010 010 100
and now we just have to translate to octal numberal radix each group separately:
110 011 111 010 010 100
6 3 7 2 2 4
giving the number 637224 as result. This same process can be inversely performed to pass from octal to binary.
In order to conduct the operation with hexadecimal numbers we only have to perform the same process but separating the binary value in groups of 4 numbers, because 16 = 2
4:
11 0011 1110 1001 0100
3 3 E 9 4
Therefore, the binary expression 110011111010010100 can be represented in C++ either as 212628 (decimal), as 0637224 (octal) or as 0x33e94 (hexadecimal).
The hexadecimal code is specially interesting in computer science since nowadays, computers are based on bytes composed of 8 binary bits and therefore each byte matches with the range that 2 hexadecimal numbers can represent. For that reason it is so frequently
used to represent values translated to or from binary base.
分享到:
相关推荐
Numerical Bases, Boolean Operations ), Information( C++ Language FAQ, History of C++, A brief description ), Sourcecode( 这个太多了,不一一列出, C++ Tutorial Sources(这是本很不错的官方c++ ...
Numerical Methods: Using MATLAB By 作者: George Lindfield – John Penny ISBN-10 书号: 0128122560 ISBN-13 书号: 9780128122563 Edition 版本: 4 出版日期: 2018-10-30 pages 页数: (608 ) $99.95 The fourth ...
Numerical Techniques in Electromagnetics, Second Edition 电磁学数值技术,fortran语言 As the availability of powerful computer resources has grown over the last three decades, the art of computation of...
《数值分析(计算方法)超经典Numerical Recipes 源码.zip》是一个包含多语言版本的数值计算方法源代码库,适用于C#开发者以及其他编程语言的学习者。Numerical Recipes是一本广泛使用的经典教材,它提供了丰富的算法...
Numerical Analysis Mathematics of Scientific Computing
Numerical recipes in C++ 第三版源代码; 经典名著,经典代码
Title: Applied Numerical Methods with MATLAB for Engineers and Scientists, 4th Edition Author: Steven Chapra Length: 720 pages Edition: 4 Language: English Publisher: McGraw-Hill Education Publication...
《Numerical Recipes in C》是一本著名的科学计算编程书籍,主要介绍了如何使用C语言进行数值计算。这本书由William H. Press、Saul A. Teukolsky、William T. Vetterling和Brian P. Flannery合著,是许多科学家和...
Numerical Python 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Numerical Methods with MATLAB provides a highly-practical reference work to assist anyone working with numerical methods. A wide range of techniques are introduced, their merits discussed and fully ...
Numerical Recipesin F90 高清pdf,Numerical Recipesin F90 高清pdf,Numerical Recipesin F90 高清pdf,Numerical Recipesin F90 高清pdf,Numerical Recipesin F90 高清pdf,Numerical Recipesin F90 高清pdf
【标题】"英文SHL官网Numerical习题"所涉及的知识点主要集中在SHL公司的数理测试方面,这种测试是企业招聘过程中常见的评估工具,尤其是针对金融、咨询、IT等行业的职位。SHL(Shl Group)是一家全球领先的测评解决...
Numerical analysis, David Kincaid, Ward Cheney 1th education
Numerical-Optimization 数值优化 第2版 高清版 pdf 电子书 带目录
### Numerical Recipes 3rd Edition – 数值分析方法库 #### 概述 《Numerical Recipes》第三版是一本在科学计算领域具有广泛影响力的经典教材与参考书籍,它由四位作者共同编著:William H. Press、Saul A. ...
数值分析工具书,有限元方法部分2,P.... Ciarlet,Handbook of Numerical Analysis. Finite Element Methods (Part 2), Numerical Methods for Solids (Part 2). Volume 4-North-Holland (1996),资源来自互联网
《Numerical Recipes头文件》是针对数值计算领域的一份重要资源,它包含了广泛使用的C++、Fortran或其他编程语言的函数库头文件。这些头文件是实现高效数值算法的基础,适用于科研、工程以及数据分析等多个领域。...
《Numerical Recipes in C/C语言数值算法》是一本经典的编程与数学结合的著作,主要针对的是使用C或C++编程语言来实现各种数值计算方法。这本书深入浅出地介绍了多种在科学计算中不可或缺的算法,并提供了详细的源...
Numerical Recipes in C 源代码,是unix的版本.
Learning Numerical Analysis(10th) 英文无水印pdf 第10版 pdf使用FoxitReader和PDF-XChangeViewer测试可以打开