.
This commit is contained in:
		
							
								
								
									
										29
									
								
								bac1/q2/fonctio/tp1/algo_q21.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								bac1/q2/fonctio/tp1/algo_q21.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
#!/bin/python
 | 
			
		||||
 | 
			
		||||
def toBinaryString(user_i:int):
 | 
			
		||||
    squares  = [2**i for i in range(32)]
 | 
			
		||||
    squares.reverse()
 | 
			
		||||
 | 
			
		||||
    ret = ''
 | 
			
		||||
    show = False
 | 
			
		||||
 | 
			
		||||
    for s in squares:
 | 
			
		||||
        if user_i & s:
 | 
			
		||||
            ret += '1'
 | 
			
		||||
            show=True
 | 
			
		||||
        else:
 | 
			
		||||
            if show:
 | 
			
		||||
                ret += '0'
 | 
			
		||||
    return ret 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def main():
 | 
			
		||||
    """
 | 
			
		||||
    Ask the user for an input
 | 
			
		||||
    """
 | 
			
		||||
    user_in = input("entrez un nombre :")
 | 
			
		||||
    print(toBinaryString(int(user_in)))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    main()
 | 
			
		||||
							
								
								
									
										85
									
								
								bac1/q2/fonctio/tp1/exercices.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								bac1/q2/fonctio/tp1/exercices.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,85 @@
 | 
			
		||||
# Exercices
 | 
			
		||||
 | 
			
		||||
## Binary
 | 
			
		||||
 | 
			
		||||
1) \\(  \\) 
 | 
			
		||||
 | 
			
		||||
2) 4095
 | 
			
		||||
 | 
			
		||||
3) 100000 (2) = 32 (10)
 | 
			
		||||
4) 000010 (2) = 2 (10)
 | 
			
		||||
5) 111111 (2) = 63 (10)
 | 
			
		||||
6) 010101 (2) = 21 (10)
 | 
			
		||||
 | 
			
		||||
7) 64 (10) = 0100 0000 (2)
 | 
			
		||||
8) 7 (10) = 0000 0100 (2)
 | 
			
		||||
9) 192 (10) = 1100 0000 (2)
 | 
			
		||||
10) 3073 (10) = 0110 0000 0001 (2)
 | 
			
		||||
 | 
			
		||||
11) 0x1010 = 4112
 | 
			
		||||
12) 0x10A0 = 4256
 | 
			
		||||
13) 0xBABE = 47806
 | 
			
		||||
 | 
			
		||||
14) 020 = 16
 | 
			
		||||
15) 072 = 58
 | 
			
		||||
 | 
			
		||||
16) sur papier = 0xCAFE
 | 
			
		||||
17) sur papier = 02001
 | 
			
		||||
 | 
			
		||||
18) 0xCAFE = 1100 1010 1111 1110
 | 
			
		||||
19) 0xCAFE = 0145376
 | 
			
		||||
20) 072 = 111010
 | 
			
		||||
 | 
			
		||||
21) > ./algo_q21.py
 | 
			
		||||
 | 
			
		||||
## Complement a 2
 | 
			
		||||
 | 
			
		||||
22)
 | 
			
		||||
23) \\( -2^11 → 2^11-1 \\)  
 | 
			
		||||
 | 
			
		||||
24) 17 = 0001 0001
 | 
			
		||||
25) -17 = 1110 1101
 | 
			
		||||
26) 255 = 1111 1111 (Imposible car pas dans l'interval)
 | 
			
		||||
27) -128 = 1000 0000
 | 
			
		||||
28) -73 = 10110111 
 | 
			
		||||
 | 
			
		||||
29)   01001111
 | 
			
		||||
   +  00000001
 | 
			
		||||
   =  01010000
 | 
			
		||||
 | 
			
		||||
30) - 10010110 = 01101010
 | 
			
		||||
 | 
			
		||||
31)   01001111
 | 
			
		||||
    + 01000001
 | 
			
		||||
    ---------
 | 
			
		||||
    = 10010000 (Overflow, le nombre n'est pas dans la range de nombre accesible sur 8 bits en ca2)
 | 
			
		||||
 | 
			
		||||
32)   00000001
 | 
			
		||||
    - 00000010
 | 
			
		||||
    ----------
 | 
			
		||||
    = 11111111
 | 
			
		||||
 | 
			
		||||
33)   00001001
 | 
			
		||||
    x 00000110
 | 
			
		||||
    ----------
 | 
			
		||||
     000010010      
 | 
			
		||||
  + 0000100100
 | 
			
		||||
  ------------
 | 
			
		||||
  = 0000110110
 | 
			
		||||
 | 
			
		||||
34)   10000001
 | 
			
		||||
    - 10000010
 | 
			
		||||
    ----------
 | 
			
		||||
    = 11111111 
 | 
			
		||||
35) - 10000000 = 011111111 (Imposible a representer sur 8 bits)
 | 
			
		||||
 | 
			
		||||
36)   00010100
 | 
			
		||||
    / 00000101
 | 
			
		||||
    ----------
 | 
			
		||||
      00000100
 | 
			
		||||
 | 
			
		||||
37)   00010111
 | 
			
		||||
    / 00001001
 | 
			
		||||
    ----------
 | 
			
		||||
      00000010 (reste 101)
 | 
			
		||||
38)
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								bac1/q2/fonctio/tp1/fonct-ordis-tp1-integers.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bac1/q2/fonctio/tp1/fonct-ordis-tp1-integers.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user