La calculatrice sait très bien le faire!!
Bon après avoir retrouvé cela, je pense que tu devrais t'en sortir.
Je ne sais plus si c'est utilisable qu'avec C++.net, mais bon, tu auras une base :
# '//TOUTES TRADUCTIONS PARTANT DU BINAIRE
# Public Function DecToBin(DecVal As Double) As String
# Dim a As Double
# a = DecVal
# For b = 1 To Int(Log(DecVal) / Log(2)) + 1
# DecToBin = CDbl(a Mod 2) & DecToBin
# a = CDbl(Int(a / 2))
# Next b
# End Function
#
# Public Function DecToHex(DecVal As Double) As String
# Dim a As Double, b As Double, c As String, d As Double
# a = DecVal
# For b = 1 To Int(Log(DecVal) / Log(16)) + 1
# d = CDbl(a Mod 16)
# Select Case d
# Case 0 To 9
# c = d
# Case Else
# c = Chr(55 + d)
# End Select
# DecToHex = c & DecToHex
# a = CDbl(Int(a / 16))
# Next b
# End Function
#
# '//TOUTES TRADUCTIONS AYANT POUR BASE LA FORME BINAIRE
# Public Function BinToDec(Bin As String) As Double
# Dim TotalDec As Double, a As Double
# For a = 1 To Len(Bin)
# TotalDec = (TotalDec * 2) + Mid(Bin, a, 1)
# Next a
# BinToDec = TotalDec
# End Function
#
# Public Function BinToHex(Bin As String) As String
# BinToHex = DecToHex(BinToDec(Bin))
# End Function
#
# '//TOUTES TRADUCTIONS AYANT POUR BASE L'HEXADÉCIMAL
# Public Function HexToDec(HexVal As String) As Double
# Dim TotalDec As Double, a As Double, c As Double
# For a = 1 To Len(HexVal)
# Select Case (Mid(HexVal, a, 1))
# Case 0 To 9
# c = (Mid(HexVal, a, 1))
# Case Else
# c = (Asc(Mid(HexVal, a, 1)) - 55)
# End Select
# TotalDec = (TotalDec * 16) + c
# Next a
# HexToDec = TotalDec
# End Function
#
# Public Function HexToBin(HexVal As String) As String
# HexToBin = DecToBin(HexToDec(HexVal))
# End Function
2007-02-25 22:43:07
·
answer #1
·
answered by chubaka_star_wars 2
·
0⤊
2⤋
une piste à explorer ici ?
http://www.cppfrance.com/codes/CONVERSION-DEC-HEX-BIN-WIN-32_11096.aspx
2007-02-25 22:43:51
·
answer #3
·
answered by Yann K 5
·
0⤊
0⤋
Fais une boucle de décalage binaire : à chaque itération :
- Tester le bit de poids faible de ton nombre :
if ((n & 1) == 0)
// le bit vaut 0
else
// le bit vaut 1
- Décale le nombre d'un bit sur la droite :
n >>= 1
C'est bête mais efficace.
2007-02-25 22:51:00
·
answer #4
·
answered by Panda 2
·
0⤊
1⤋