IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

Générer matrice de binaires


Sujet :

Java

  1. #1
    Membre régulier
    Homme Profil pro
    .
    Inscrit en
    Mai 2012
    Messages
    120
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : .

    Informations forums :
    Inscription : Mai 2012
    Messages : 120
    Points : 81
    Points
    81
    Par défaut Générer matrice de binaires
    Bonjour tout le monde
    je souhaite écrire un programme java me permettant de générer une matrice de binaire à partir d'une String donnée
    et par la même occasion ajouter un bit a la fin de chaque ligne et colonne.
    J'ai du mal a le faire
    Merci

  2. #2
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut
    Salut
    Ce serait bien si tu pouvais donner un début de code et expliquer exactement ou tu bloques s'il te plait

  3. #3
    Membre régulier
    Homme Profil pro
    .
    Inscrit en
    Mai 2012
    Messages
    120
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : .

    Informations forums :
    Inscription : Mai 2012
    Messages : 120
    Points : 81
    Points
    81
    Par défaut
    Citation Envoyé par Laine Voir le message
    Salut
    Ce serait bien si tu pouvais donner un début de code et expliquer exactement ou tu bloques s'il te plait
    voici ce que j'ai essayé de faire:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
     
    public class MAT {
     
     
    	public static String toBinary(char c) {
     
    		String s = Integer.toBinaryString(c);
     
    		int n = Integer.bitCount(c);
    		if (n % 2 == 0) {
    			return s + '0';
    		} else {
    			return s  + '1';
    		}
    	}
    	public static char[] tochar(String str)
    	{
    		char []tab;
    		tab=new char[str.length()];
    		for(int i=0;i<str.length();i++)
    		{
    			tab[i]=str.charAt(i);
    		}
    		return tab;
    	}
    	public static void main(String[] args) {
    		String maChaine = "HELLOWORLD";	
    		char [] tab;
    		char [][]mat;
    		for (int i = 0; i < maChaine.length(); i++) {
    			String s = Integer.toBinaryString(maChaine.charAt(i));
    			s = toBinary(maChaine.charAt(i));
    			tab=new char [s.length()];
    			tab=tochar(s);
    			mat=new char[s.length()][8];
    			for(int j=0;j<8;j++)
    			{
    				mat[i]=tab;
    			}
    		System.out.println(mat[i]);
    		}
    à partir de ce code je voudrais générer une matrice a partir d'une String donnée par la suite ajouter un bit a la fin de chaque ligne et chaque colonne
    Merci a vous tout en espérant été clair

  4. #4
    Membre confirmé

    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2011
    Messages
    181
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2011
    Messages : 181
    Points : 519
    Points
    519
    Billets dans le blog
    1
    Par défaut
    Slt.
    Tu pourrais commencer d'abord par convertir ton String en un tableau de int [], chaque case du tableau correspondra a la valeur d'un caractère de la chaine. En suite faire des et logiques pour obtenir la valeur de chacune des bit de l'octect :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    public static byte[] toByteArray (char[] array) {//Conversion char [] en byte []
    		return toByteArray(array, Charset.defaultCharset());
        }//toByteArray
        /**
         * 
         * @param array
         * @param charset
         * @return 
         */
        public static byte[] toByteArray (char[] array, Charset c){//toByteArray
    		CharBuffer cbuf = CharBuffer.wrap(array);
    		ByteBuffer bbuf = charset.encode(cbuf);
    		return bbuf.array();
        }//toByteArray
    Pour le test bit par bit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    String s = "Java";
    int [] tab = arrayByteToArrayInt (toByteArray (s.toCharArray ())));
     tab [0] = tab [0] & 0x01;
            if (tab [0] > 0)
                System.out.println ("1");
            else
                System.out.println ("0");
            tab [0] = tab [0] & 0x02;
            if (tab [0] > 0)
                System.out.println ("1");
            else
                System.out.println ("0");
    ...
    ...
    ...
    Pour la conversion byte->int, une simple affectation suffira (il va y avoir un cast).
    Bon courage

  5. #5
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut
    Si ceci est le résultat que tu veux obtenir:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    H: [1, 0, 0, 1, 0, 0, 0, 0]
    E: [1, 0, 0, 0, 1, 0, 1, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    O: [1, 0, 0, 1, 1, 1, 1, 1]
    W: [1, 0, 1, 0, 1, 1, 1, 1]
    O: [1, 0, 0, 1, 1, 1, 1, 1]
    R: [1, 0, 1, 0, 0, 1, 0, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    D: [1, 0, 0, 0, 1, 0, 0, 0]
    Voici ton code que j'ai quelque peu modifié
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    import java.util.Arrays;
     
    public class MAT {
     
    	public static String toBinary(char c) {
     
    		String s= Integer.toBinaryString(c);
    		int n= Integer.bitCount(c);
     
    		if (n % 2 == 0)
    			return s+"0";
    		else
        		return s+"1";
        }
     
        public static void main(String[] args) {
     
        	String maChaine= "HELLOWORLD";
        	char[][] mat= new char[maChaine.length()][8];
        	String s;
        	char c;
     
        	for(int i=0; i<maChaine.length(); i++) {
        		c= maChaine.charAt(i);
        		s= toBinary(c);
        		mat[i]= s.toCharArray();
     
        		System.out.println(c+": "+Arrays.toString(mat[i]));
        	}
        }
    }
    Pas besoin d'utiliser ta méthode "tochar", il y'a déjà une fonction pour ça: machaine.toCharArray().
    Sinon les autres modifications sont des modifications d'affectations.

  6. #6
    Membre régulier
    Homme Profil pro
    .
    Inscrit en
    Mai 2012
    Messages
    120
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : .

    Informations forums :
    Inscription : Mai 2012
    Messages : 120
    Points : 81
    Points
    81
    Par défaut
    Citation Envoyé par Laine Voir le message
    Si ceci est le résultat que tu veux obtenir:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    H: [1, 0, 0, 1, 0, 0, 0, 0]
    E: [1, 0, 0, 0, 1, 0, 1, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    O: [1, 0, 0, 1, 1, 1, 1, 1]
    W: [1, 0, 1, 0, 1, 1, 1, 1]
    O: [1, 0, 0, 1, 1, 1, 1, 1]
    R: [1, 0, 1, 0, 0, 1, 0, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    D: [1, 0, 0, 0, 1, 0, 0, 0]
    Voici ton code que j'ai quelque peu modifié
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    import java.util.Arrays;
     
    public class MAT {
     
    	public static String toBinary(char c) {
     
    		String s= Integer.toBinaryString(c);
    		int n= Integer.bitCount(c);
     
    		if (n % 2 == 0)
    			return s+"0";
    		else
        		return s+"1";
        }
     
        public static void main(String[] args) {
     
        	String maChaine= "HELLOWORLD";
        	char[][] mat= new char[maChaine.length()][8];
        	String s;
        	char c;
     
        	for(int i=0; i<maChaine.length(); i++) {
        		c= maChaine.charAt(i);
        		s= toBinary(c);
        		mat[i]= s.toCharArray();
     
        		System.out.println(c+": "+Arrays.toString(mat[i]));
        	}
        }
    }
    Pas besoin d'utiliser ta méthode "tochar", il y'a déjà une fonction pour ça: machaine.toCharArray().
    Sinon les autres modifications sont des modifications d'affectations.

    Merci à vous tous lainec est effectivement ce que je cherchais
    mais est ce qu'il est possible d'ignorer les caractères spéciaux

  7. #7
    Membre régulier
    Homme Profil pro
    .
    Inscrit en
    Mai 2012
    Messages
    120
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : .

    Informations forums :
    Inscription : Mai 2012
    Messages : 120
    Points : 81
    Points
    81
    Par défaut
    Citation Envoyé par mohamine1989 Voir le message
    Slt.
    Tu pourrais commencer d'abord par convertir ton String en un tableau de int [], chaque case du tableau correspondra a la valeur d'un caractère de la chaine. En suite faire des et logiques pour obtenir la valeur de chacune des bit de l'octect :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    public static byte[] toByteArray (char[] array) {//Conversion char [] en byte []
    		return toByteArray(array, Charset.defaultCharset());
        }//toByteArray
        /**
         * 
         * @param array
         * @param charset
         * @return 
         */
        public static byte[] toByteArray (char[] array, Charset c){//toByteArray
    		CharBuffer cbuf = CharBuffer.wrap(array);
    		ByteBuffer bbuf = charset.encode(cbuf);
    		return bbuf.array();
        }//toByteArray
    Pour le test bit par bit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    String s = "Java";
    int [] tab = arrayByteToArrayInt (toByteArray (s.toCharArray ())));
     tab [0] = tab [0] & 0x01;
            if (tab [0] > 0)
                System.out.println ("1");
            else
                System.out.println ("0");
            tab [0] = tab [0] & 0x02;
            if (tab [0] > 0)
                System.out.println ("1");
            else
                System.out.println ("0");
    ...
    ...
    ...
    Pour la conversion byte->int, une simple affectation suffira (il va y avoir un cast).
    Bon courage
    Merci bien mais à vue d’œil le code sera long

  8. #8
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut
    mais est ce qu'il est possible d'ignorer les caractères spéciaux
    Oui bien sûr, ce code pourrait t'aider:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    public boolean isLetter(char ch) {
         return Character.toString(ch).matches("[a-zA-Z]");
    }
    Cette fonction permet de tester si un caractère est une lettre inclue entre a et z, en majscule et minuscule.

    Et si tu veux inclure les accents aussi, utilise:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Character.isLetter(char);
    Dans ce cas la taille de ton tableau mat ne sera plus la taille de ta chaîne String, tu peux laisser ton code ainsi ce n'est pas vraiment un problème ou tu peux utiliser une ArrayList pour mat. Mais ce n'est pas obligatoire.

  9. #9
    Membre régulier
    Homme Profil pro
    .
    Inscrit en
    Mai 2012
    Messages
    120
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : .

    Informations forums :
    Inscription : Mai 2012
    Messages : 120
    Points : 81
    Points
    81
    Par défaut
    Citation Envoyé par Laine Voir le message
    Oui bien sûr, ce code pourrait t'aider:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    public boolean isLetter(char ch) {
         return Character.toString(ch).matches("[a-zA-Z]");
    }
    Cette fonction permet de tester si un caractère est une lettre inclue entre a et z, en majscule et minuscule.

    Et si tu veux inclure les accents aussi, utilise:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Character.isLetter(char);
    Dans ce cas la taille de ton tableau mat ne sera plus la taille de ta chaîne String, tu peux laisser ton code ainsi ce n'est pas vraiment un problème ou tu peux utiliser une ArrayList pour mat. Mais ce n'est pas obligatoire.
    Genial merci encore

  10. #10
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut
    Y'a pas de quoi

  11. #11
    Membre confirmé

    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2011
    Messages
    181
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2011
    Messages : 181
    Points : 519
    Points
    519
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par proc02
    Merci bien mais à vue d’œil le code sera long
    De rien

  12. #12
    Membre régulier
    Homme Profil pro
    .
    Inscrit en
    Mai 2012
    Messages
    120
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : .

    Informations forums :
    Inscription : Mai 2012
    Messages : 120
    Points : 81
    Points
    81
    Par défaut
    Citation Envoyé par Laine Voir le message
    Y'a pas de quoi
    Bonjour
    L'opération que j'ai eu à faire sur les lignes j'aimerais faire la même chose pour les colonnes vous avez une idée
    Voici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    public static String toBinary(char c) {
     
    		String s= Integer.toBinaryString(c);
    		int n= Integer.bitCount(c);
     
    		if (n % 2 == 0)
    			return s+"0";
    		else
        		return s+"1";
        }
    Merci

  13. #13
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut
    L'opération que j'ai eu à faire sur les lignes j'aimerais faire la même chose pour les colonnes
    Explique moi, ce que tu veux faire c'est à partir de la matrice que tu as obtenu:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    H: [1, 0, 0, 1, 0, 0, 0, 0]
    E: [1, 0, 0, 0, 1, 0, 1, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    O: [1, 0, 0, 1, 1, 1, 1, 1]
    W: [1, 0, 1, 0, 1, 1, 1, 1]
    O: [1, 0, 0, 1, 1, 1, 1, 1]
    R: [1, 0, 1, 0, 0, 1, 0, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    D: [1, 0, 0, 0, 1, 0, 0, 0]
    Récupérer chaque colonne puis rajouter un 1 ou 0 selon le contenu de la colonne ?

  14. #14
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut
    Si c'est bien ce que tu veux, je t'ai concocter un code qui donne ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    H: [1, 0, 0, 1, 0, 0, 0, 0]
    E: [1, 0, 0, 0, 1, 0, 1, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    O: [1, 0, 0, 1, 1, 1, 1, 1]
    W: [1, 0, 1, 0, 1, 1, 1, 1]
    O: [1, 0, 0, 1, 1, 1, 1, 1]
    R: [1, 0, 1, 0, 0, 1, 0, 1]
    L: [1, 0, 0, 1, 1, 0, 0, 1]
    D: [1, 0, 0, 0, 1, 0, 0, 0]
    +: [0, 0, 0, 0, 0, 0, 0, 0]
    Le voici
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    import java.util.Arrays;
     
    import javax.naming.BinaryRefAddr;
     
     
    public class MAT {
     
    	public static String toBinaryRow(char c) {
     
    		String s= Integer.toBinaryString(c);
    		int n= Integer.bitCount(c);
     
    		if (n % 2 == 0)
    			return s+"0";
    		else
        		return s+"1";
        }
     
    	public static char toBinaryCol(String s) {
     
    		int a= Integer.parseInt(s, 2);   //convertir la chaine de binaire en entier
    		int n= Integer.bitCount(a);     // compter le nombre de 1 contenu dans le binaire de l'entier
     
    		if (n % 2 == 0)
    			return '0';
    		else
        		return '1';
        }
     
        public static void main(String[] args) {
     
        	String maChaine= "HELLOWORLD";
        	int nbRow= maChaine.length() + 1;
        	int nbCol= 8;
        	char[][] mat= new char[nbRow][nbCol];
        	String s;
        	char c;
     
        	for(int i=0; i<nbRow-1; i++) {  //traiter chaque caractère de la chaine maChaine
        		c= maChaine.charAt(i);
        		s= toBinaryRow(c);
        		mat[i]= s.toCharArray();
        	}
     
        	StringBuilder binary;
     
        	for(int j=0; j<nbCol; j++) {  //traiter chaque colonne de mat
        		binary= new StringBuilder();
     
        		for(int i=0; i<nbRow-1; i++)
        			binary.append(mat[i][j]); //concaténation des cases pour la colonne traitée
     
        		String str= ""+binary; 
        		mat[nbRow-1][j]= toBinaryCol(str);		
        	}
     
        	for(int i=0; i<nbRow-1; i++)  
        		System.out.println(maChaine.charAt(i)+": "+Arrays.toString(mat[i]));
        	System.out.println("+: "+Arrays.toString(mat[nbRow-1]));
        }
    }
    Il est commenté. J'espère que ça te conviendra

  15. #15
    Membre régulier
    Homme Profil pro
    .
    Inscrit en
    Mai 2012
    Messages
    120
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : .

    Informations forums :
    Inscription : Mai 2012
    Messages : 120
    Points : 81
    Points
    81
    Par défaut
    Le voici
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    import java.util.Arrays;
     
    import javax.naming.BinaryRefAddr;
     
     
    public class MAT {
     
    	public static String toBinaryRow(char c) {
     
    		String s= Integer.toBinaryString(c);
    		int n= Integer.bitCount(c);
     
    		if (n % 2 == 0)
    			return s+"0";
    		else
        		return s+"1";
        }
     
    	public static char toBinaryCol(String s) {
     
    		int a= Integer.parseInt(s, 2);   //convertir la chaine de binaire en entier
    		int n= Integer.bitCount(a);     // compter le nombre de 1 contenu dans le binaire de l'entier
     
    		if (n % 2 == 0)
    			return '0';
    		else
        		return '1';
        }
     
        public static void main(String[] args) {
     
        	String maChaine= "HELLOWORLD";
        	int nbRow= maChaine.length() + 1;
        	int nbCol= 8;
        	char[][] mat= new char[nbRow][nbCol];
        	String s;
        	char c;
     
        	for(int i=0; i<nbRow-1; i++) {  //traiter chaque caractère de la chaine maChaine
        		c= maChaine.charAt(i);
        		s= toBinaryRow(c);
        		mat[i]= s.toCharArray();
        	}
     
        	StringBuilder binary;
     
        	for(int j=0; j<nbCol; j++) {  //traiter chaque colonne de mat
        		binary= new StringBuilder();
     
        		for(int i=0; i<nbRow-1; i++)
        			binary.append(mat[i][j]); //concaténation des cases pour la colonne traitée
     
        		String str= ""+binary; 
        		mat[nbRow-1][j]= toBinaryCol(str);		
        	}
     
        	for(int i=0; i<nbRow-1; i++)  
        		System.out.println(maChaine.charAt(i)+": "+Arrays.toString(mat[i]));
        	System.out.println("+: "+Arrays.toString(mat[nbRow-1]));
        }
    }
    Il est commenté. J'espère que ça te conviendra[/QUOTE]

    you know Merci infiniment

  16. #16
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut
    De rien avec plaisir

  17. #17
    Membre régulier
    Homme Profil pro
    .
    Inscrit en
    Mai 2012
    Messages
    120
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : .

    Informations forums :
    Inscription : Mai 2012
    Messages : 120
    Points : 81
    Points
    81
    Par défaut
    Citation Envoyé par Laine Voir le message
    De rien avec plaisir
    Bonjour encore une foi Laine
    je voudrais savoir s'il une autre approche pour faire court le code
    Si oui elle m’intéresse.
    Merci

  18. #18
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut
    Bonsoir
    étant donné que les lettres de ta chaine constituent les lignes de ta matrices, que tu as besoin de remplir toute les lignes de ta matrice avant de traiter la dernière ligne, personnellement je ne vois pas une autre façon de faire je suis désolée.

  19. #19
    Membre régulier
    Homme Profil pro
    .
    Inscrit en
    Mai 2012
    Messages
    120
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : .

    Informations forums :
    Inscription : Mai 2012
    Messages : 120
    Points : 81
    Points
    81
    Par défaut
    Citation Envoyé par Laine Voir le message
    Bonsoir
    étant donné que les lettres de ta chaine constituent les lignes de ta matrices, que tu as besoin de remplir toute les lignes de ta matrice avant de traiter la dernière ligne, personnellement je ne vois pas une autre façon de faire je suis désolée.
    Juste une curiosité sinon

  20. #20
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Générer des fichiers binaires
    Par scolyo dans le forum Langage
    Réponses: 4
    Dernier message: 04/11/2010, 09h10
  2. Générer un vecteur binaire 8bits aléatoire
    Par mirva dans le forum MATLAB
    Réponses: 2
    Dernier message: 16/12/2008, 16h47
  3. Générer des séquences binaires
    Par Contrec dans le forum C#
    Réponses: 16
    Dernier message: 03/12/2008, 15h46
  4. générer un fichier binaire OCTET par OCTET
    Par Septembre84 dans le forum Entrée/Sortie
    Réponses: 11
    Dernier message: 20/03/2008, 16h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo