Click here to Skip to main content
12,954,464 members (78,322 online)
   

Java

 
AnswerRe: For Java Project Pin
Richard MacCutchan18-Jan-13 23:00
mvpRichard MacCutchan18-Jan-13 23:00 
AnswerRe: For Java Project Pin
cubocik22-Jan-13 2:08
membercubocik22-Jan-13 2:08 
AnswerRe: For Java Project Pin
Sandeep Mewara22-Jan-13 2:39
mvpSandeep Mewara22-Jan-13 2:39 
AnswerRe: For Java Project Pin
Swarnendu0931-Jan-13 16:58
memberSwarnendu0931-Jan-13 16:58 
Questionc Pin
ravi bhukya17-Jan-13 23:38
memberravi bhukya17-Jan-13 23:38 
AnswerRe: c Pin
Richard MacCutchan18-Jan-13 2:51
mvpRichard MacCutchan18-Jan-13 2:51 
AnswerRe: c Pin
ProgramFOX18-Jan-13 23:58
member ProgramFOX18-Jan-13 23:58 
QuestionHow to convert byte array to hex string Pin
IICTECH17-Jan-13 17:57
memberIICTECH17-Jan-13 17:57 
Hi All,
I got a piece of code from google to convert byte array to hex string...i din't understand few lines of code can any on ehelp me to understand ?? Smile | :)

<br />
<pre lang="cs">public static String CellKeysGeneration() {<br />
<br />
        byte[] btba = new byte[5];<br />
<br />
        Random r = new Random();<br />
<br />
        r.nextBytes(btba);<br />
<br />
        for (int i = 0; i < btba.length; i++) {<br />
<br />
            btba[i] = btba[i];<br />
<br />
        }<br />
        String str = tohexString(btba);<br />
        return str;<br />
    }<br />
<br />
    public static String tohexString(byte[] bytes) {<br />
<br />
        StringBuffer sb = new StringBuffer(bytes.length * 2);<br />
<br />
        for (int i = 0; i < bytes.length; i++) {<br />
            sb.append(tohex(bytes[i] >> 4));<br />
            sb.append(tohex(bytes[i]));<br />
<br />
        }<br />
<br />
        return sb.toString();<br />
<br />
    }<br />
<br />
    public static char tohex(int nibble) {<br />
<br />
        final char[] hexdigit = { '0', '1', '2', '3', '4', '5', '6', '7', '8',<br />
                '9', 'A', 'B', 'C', 'D', 'E' , 'F' };<br />
<br />
        return hexdigit[nibble & 0xF];<br />
    }</pre><br />
<br />


In above three functions,

1) I dint understand why in toHex function we are always performing "and" operartion with 0xF.

2) I dint understand why in tohexString function we are performing ">>" operation with 4.

Can any one help me to understand toHexString and toHex functions ?? Smile | :)

Thanks in advance !
AnswerRe: How to convert byte array to hex string Pin
Richard MacCutchan17-Jan-13 23:14
mvpRichard MacCutchan17-Jan-13 23:14 
GeneralRe: How to convert byte array to hex string Pin
IICTECH18-Jan-13 2:02
memberIICTECH18-Jan-13 2:02 
GeneralRe: How to convert byte array to hex string Pin
Richard MacCutchan18-Jan-13 2:50
mvpRichard MacCutchan18-Jan-13 2:50 
QuestionImage Store in MySQL db Pin
ayemyamya17-Jan-13 16:20
memberayemyamya17-Jan-13 16:20 
AnswerRe: Image Store in MySQL db Pin
Richard MacCutchan17-Jan-13 23:13
mvpRichard MacCutchan17-Jan-13 23:13 
AnswerRe: Image Store in MySQL db Pin
sakurahito27-Jan-13 21:05
membersakurahito27-Jan-13 21:05 
QuestionHow to login server of router? Pin
ngoanrazor17-Jan-13 15:11
memberngoanrazor17-Jan-13 15:11 
AnswerRe: How to auto login server of router? Pin
ngoanrazor20-Jan-13 2:45
memberngoanrazor20-Jan-13 2:45 
GeneralRe: How to auto login server of router? Pin
cubocik22-Jan-13 2:15
membercubocik22-Jan-13 2:15 
GeneralRe: How to auto login server of router? Pin
ngoanrazor22-Jan-13 14:01
memberngoanrazor22-Jan-13 14:01 
GeneralRe: How to auto login server of router? Pin
cubocik29-Jan-13 1:46
membercubocik29-Jan-13 1:46 
AnswerRe: How to login server of router? Pin
jschell22-Jan-13 8:15
memberjschell22-Jan-13 8:15 
GeneralRe: How to login server of router? Pin
ngoanrazor22-Jan-13 14:03
memberngoanrazor22-Jan-13 14:03 
GeneralRe: How to login server of router? Pin
jschell23-Jan-13 8:45
memberjschell23-Jan-13 8:45 
GeneralRe: How to login server of router? Pin
ngoanrazor23-Jan-13 14:56
memberngoanrazor23-Jan-13 14:56 
Questionam a beginner Pin
onyebumichael15-Jan-13 9:42
grouponyebumichael15-Jan-13 9:42 
AnswerRe: am a beginner Pin
Richard MacCutchan15-Jan-13 22:54
mvpRichard MacCutchan15-Jan-13 22:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 28 May 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid