How are decimal numbers converted to hexadecimal and hexadecimal using the hex and oct formatting flags or are they stored in several forms? + How to determine which system is used to represent negative hexadecimal and hexadecimal numbers?

  • one
    All numbers are stored in binary number system. - Alexcei Shmakov

1 answer 1

Numbers are stored in binary form, in the form of sets of bits.

When outputting, the calculation is simply performed, how exactly to display these numbers. Well, roughly speaking, how to display in octal 12? The remainder of the division by 8 - 4, which means we write to the least significant digit 4; divide - we get 1. The next iteration: the remainder of the division by 8 - 1 (the next digit), the division gives 0. So, in the octal record it is 14 ...

As for negative numbers, as far as I remember the standard, when entering and outputting in hexadecimal and octal, the numbers are converted to an unsigned type, so there’s no need to talk about a sign. If you mean a binary format, then the standard, as far as I remember, does not define one, but the addition to the two is usually used.

  • Those. first from binary translates to 10-dnuyu, and then divides by 8.16? Why can't I translate right away - vitya312
  • @ vitya312 Naturally, all these actions are performed in a binary representation. I just described the principle with an example. - Harry
  • So from 2nd to 16th and 8th is translated as simply replacing 4 and 3 figures, respectively, with the numbers of these systems - vitya312
  • @ vitya312 I have a feeling that we are talking about different things. Once again - what exactly do you not understand? And what is the allocation of 3 (4) bits as not the operation of the remainder of dividing by 8 (16), and discarding them - the operation of dividing by 8 (16)? - Harry
  • one
    @ vitya312 In general, int is usually 32 bits, so that -80 in the form of int has a bit representation of 11111111111111111111111110110000 ... 0110000 is 48. See ru.wikipedia.org/wiki/… - Harry