Перевод чисел из двоичной системы счисления в шестнадцатеричную систему счисления

code: #basic
rem первод чисел из 2 сс в 16 сс
CLS
INPUT  "Введите число "; A$
n =1 : k$ = "" : x$ = ""
10 k$ = MID$ (a$, n,  1)
IF k$ = "." THEN n =n-1 :GOTO 20 ELSE x$ = X$ +k$ :n = n+1:GOTO 10
20 IF n MOD 4 = 1 THEN x$ = "000" +x$
IF n MOD 4 = 2 THEN x$ = "00" +x$
IF n MOD 4 = 3 THEN x$ = "0" +x$
PRINT "Получите шестезначное число";
FOR i =1 TO LEN (x$) STEP 4
b$ = MID$(x$, i, 4)
IF b$ = "0000" THEN b1$ = "0"
IF b$ = "0001" THEN b1$ = "1"
IF b$ = "0010" THEN b1$ = "2"
IF b$ = "0011" THEN b1$ = "3"
IF b$ = "0100" THEN b1$ = "4"
IF b$ = "0101" THEN b1$ = "5"
IF b$ = "0110" THEN b1$ = "6"
IF b$ = "0111" THEN b1$ = "7"
IF b$ = "1000" THEN b1$ = "8"
IF b$ = "1001" THEN b1$ = "9"
IF b$ = "1010" THEN b1$ = "A"
IF b$ = "1011" THEN b1$ = "B"
IF b$ = "1100" THEN b1$ = "C"
IF b$ = "1101" THEN b1$ = "D"
IF b$ = "1110" THEN b1$ = "E"
IF b$ = "1111" THEN b1$ = "F"
PRINT b1$;
NEXT i
PRINT ".";
FOR  i = n + 2 TO LEN (a$) STEP 4
IF (LEN(a$) - n -1) MOD 4 = 1 THEN a$ = a$ + "000"
IF (LEN(a$) - n -1) MOD 4 = 2 THEN a$ = a$ + "00"
IF (LEN(a$) - n -1) MOD 4 = 3 THEN a$ = a$ + "0"
y$ = MID$ (a$, i ,4)
IF y$  = "0000" THEN y1$= "0"
IF y$ = "0001" THEN y1$ = "1"
IF y$ = "0010" THEN y1$ = "2"
IF y$ = "0011" THEN y1$ = "3"
IF y$ = "0100" THEN y1$ = "4"
IF y$ = "0101" THEN y1$ = "5"
IF y$ = "0110" THEN y1$ = "6"
IF y$ = "0111" THEN y1$ = "7"
IF y$ = "1000" THEN y1$= "8"
IF y$ = "1001" THEN y1$ = "9"
IF y$ = "1010" THEN y1$ = "A"
IF y$ = "1011" THEN y1$= "B"
IF y$ = "1100" THEN y1$ = "C"
IF y$ = "1101" THEN y1$ = "D"
IF y$ = "1110" THEN y1$ = "E"
IF y$= "1111" THEN y1$ = "F"
PRINT y1$;
NEXT i
END
Поделиться:

Похожие статьи: