Python alphabet with binary and hexadecimal code

Hi programmers out there, I would like to know how I in Python 3, an alphabet with binary and hexadecimal code as List Program the. About as it should look like: A hex code binary code B hex code binary code ...

Preferably with as few lines as possible.

thank you in advance

The best answer

Two lines:

for ($ i = ord ( 'A'); $ i <= ord ( 'Z'); $ i ++)
printf ( "% c => #% 02X =>% 08b \ n", $ i, $ i, $ i);

This provides the following output:

'A' => # 41 => 01000001
'B' => # 42 => 01000010
'C' => # 43 => 01000011
'D' => # 44 => 01000100
'E' => # 45 => 01000101
'F' => # 46 => 01000110
'G' => # 47 => 01000111
'H' => # 48 => 01001000
'I' => # 49 => 01001001
'J' => # 4A => 01001010
'K' => # 4B => 01001011
'L' => # 4C => 01001100
'M' => # 4D => 01001101
'N' => # 4E => 01001110
'O' => # 4F => 01001111
'P' => # 50 => 01010000
'Q' => # 51 => 01010001
'R' => # 52 => 01010010
'S' => # 53 => 01010011
'T' => # 54 => 01010100
'U' => # 55 => 01010101
'V' => # 56 => 01010110
'W' => # 57 => 01010111
'X' => # 58 => 01011000
'Y' => # 59 => 01011001
'Z' => # 5A => 01011010

If you have the output as HTML want, you should replace the "\ n" by a "<br /> \ n" at the end of the format string of printf (), otherwise you have above output in a single line! :)

Have fun! :)

Thanks worked

Date: 2019-04-26 Views: 2

Related articles

Links

Domicile|Sante|

Copyright (C) 2019 m3tch.com, All Rights Reserved.

M3tch all rights reserved.

processed in 1.162 (s). 10 q(s)