Click here to Skip to main content
15,899,314 members
Home / Discussions / C#
   

C#

 
GeneralRe: Hex to UUEncode in C# Pin
NJdotnetdev20-Jan-15 3:24
NJdotnetdev20-Jan-15 3:24 
GeneralRe: Hex to UUEncode in C# Pin
OriginalGriff20-Jan-15 3:35
mveOriginalGriff20-Jan-15 3:35 
GeneralRe: Hex to UUEncode in C# Pin
NJdotnetdev20-Jan-15 3:43
NJdotnetdev20-Jan-15 3:43 
GeneralRe: Hex to UUEncode in C# Pin
OriginalGriff20-Jan-15 4:01
mveOriginalGriff20-Jan-15 4:01 
GeneralRe: Hex to UUEncode in C# Pin
NJdotnetdev20-Jan-15 4:42
NJdotnetdev20-Jan-15 4:42 
GeneralRe: Hex to UUEncode in C# Pin
OriginalGriff20-Jan-15 4:57
mveOriginalGriff20-Jan-15 4:57 
GeneralRe: Hex to UUEncode in C# Pin
NJdotnetdev20-Jan-15 5:00
NJdotnetdev20-Jan-15 5:00 
GeneralRe: Hex to UUEncode in C# Pin
OriginalGriff20-Jan-15 5:18
mveOriginalGriff20-Jan-15 5:18 
OK.
Look at the line you worte:
C#
string temp = String.Format("{0:X02}{1:X02}{2:X02}", (output & 0xFF0000FF) >> 0, (output & 0xFF00FF00) >> 8, (output & 0xFFFF0000) >> 16);

Let's reformat that so it's more obvious whats happening:
C#
string temp = String.Format("{0:X02}{1:X02}{2:X02}", 
                            (output & 0xFF0000FF) >> 0, 
                            (output & 0xFF00FF00) >> 8, 
                            (output & 0xFFFF0000) >> 16);

The String.Format bit is trivial: output each of three values as two hex digits with leadign zeros if necessary.
The other three do the same thing, just they work on three different bytes of the input number. (Except if you pass though a negative number, it's all going to fail badly - that's the "FF" ate th left hand side adding in the top byte to all three vlaues)
The top one extracts the least significant byte: x & 0x00000FF
The middle one extracts the middle byte value x & 0x00FF00, then shifts if down eight bit places to move it to the least significant position.
The top one does teh same with the top value of teh three, moving it 16 bits down.
So if the output variable held 0x00FEDCBA:
The first part extracts 0xBA
The second     extracts 0xDC 
The third      extracts 0xFE

Which is then converted to a string "BADCFE" - little endian format because the least significant byte is first.

So to reverse it, break the string into three parts with SubString, convert each part with int.Parse(part, NumberStyles.HexNumber) and use << to shift it back where it came from.

Simple enough?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: Hex to UUEncode in C# Pin
NJdotnetdev20-Jan-15 5:41
NJdotnetdev20-Jan-15 5:41 
GeneralRe: Hex to UUEncode in C# Pin
OriginalGriff20-Jan-15 5:43
mveOriginalGriff20-Jan-15 5:43 
QuestionMicrosoft Enterprise Library 5.0 Pin
Member 397562920-Jan-15 1:19
Member 397562920-Jan-15 1:19 
AnswerRe: Microsoft Enterprise Library 5.0 Pin
OriginalGriff20-Jan-15 2:51
mveOriginalGriff20-Jan-15 2:51 
QuestionTraffic laws Project Pin
zayno19-Jan-15 2:45
zayno19-Jan-15 2:45 
AnswerRe: Traffic laws Project Pin
RUs12319-Jan-15 3:07
RUs12319-Jan-15 3:07 
GeneralRe: Traffic laws Project Pin
zayno19-Jan-15 3:13
zayno19-Jan-15 3:13 
GeneralRe: Traffic laws Project Pin
RUs12319-Jan-15 3:21
RUs12319-Jan-15 3:21 
AnswerRe: Traffic laws Project Pin
Dave Kreskowiak19-Jan-15 4:38
mveDave Kreskowiak19-Jan-15 4:38 
AnswerRe: Traffic laws Project Pin
Afzaal Ahmad Zeeshan19-Jan-15 5:03
professionalAfzaal Ahmad Zeeshan19-Jan-15 5:03 
AnswerRe: Traffic laws Project Pin
V.20-Jan-15 1:59
professionalV.20-Jan-15 1:59 
Questionaugmenting reality project (Affix Center Sofech Services Pvt. Ltd) Pin
ishaan279118-Jan-15 23:13
ishaan279118-Jan-15 23:13 
AnswerRe: augmenting reality project (Affix Center Sofech Services Pvt. Ltd) Pin
OriginalGriff18-Jan-15 23:23
mveOriginalGriff18-Jan-15 23:23 
QuestionThe Max() linq extension method on a List<MyClass> [Solved] Pin
TMattC18-Jan-15 23:06
TMattC18-Jan-15 23:06 
AnswerRe: The Max() linq extension method on a List<MyClass> Pin
TMattC18-Jan-15 23:16
TMattC18-Jan-15 23:16 
AnswerRe: The Max() linq extension method on a List<MyClass> Pin
Richard Deeming18-Jan-15 23:19
mveRichard Deeming18-Jan-15 23:19 
QuestionSignalR - Realtime events - Database communication - thoughts? Pin
Angelika S Michel17-Jan-15 16:39
Angelika S Michel17-Jan-15 16:39 

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.