Click here to Skip to main content
15,877,547 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: To convert a DAT file to a BMP file Pin
sgd.ind1-Nov-09 3:21
sgd.ind1-Nov-09 3:21 
GeneralRe: To convert a DAT file to a BMP file Pin
Code-o-mat1-Nov-09 3:46
Code-o-mat1-Nov-09 3:46 
Questionconvert md5 values to decimal Pin
nuttynibbles31-Oct-09 20:14
nuttynibbles31-Oct-09 20:14 
AnswerRe: convert md5 values to decimal Pin
CPallini31-Oct-09 21:20
mveCPallini31-Oct-09 21:20 
Questionreverse division to convert decimals to dinary Pin
Omegaclass31-Oct-09 19:57
Omegaclass31-Oct-09 19:57 
AnswerRe: reverse division to convert decimals to dinary Pin
CPallini31-Oct-09 21:04
mveCPallini31-Oct-09 21:04 
GeneralRe: reverse division to convert decimals to dinary Pin
Omegaclass31-Oct-09 21:36
Omegaclass31-Oct-09 21:36 
GeneralRe: reverse division to convert decimals to dinary Pin
CPallini1-Nov-09 6:32
mveCPallini1-Nov-09 6:32 
In order to obtain the correct result (i.e. reversed bits) using your method, you need to multiply instead of dividing. At every iteration you have to:
  1. Test the most significative bit of the number.
  2. miltiply the number by two, so that the most significative bit is replaced by its adjacent one (the next you'll test).


In my code I replaced multiplication by 2 with left shift that is faster.
Dealing with MSB (most significative bit) is a little trcky since its position depends on the data type, i.e. it is bit 7 for unsigned chars, bit 15 for 2-byte data types (like short on my machine) and bit 31 for 4-byte data types (like unsigned int on my PC) hence the 'messy' lines in my routine, for instance:

const int SIZE = sizeof(k) << 3;
Here SIZE is set to the length, expressed in bits, of k (sizeof operator returns bytes, I multiply by 8 using, again, left shift operator).
Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke

[My articles]

GeneralRe: reverse division to convert decimals to dinary Pin
Omegaclass1-Nov-09 10:10
Omegaclass1-Nov-09 10:10 
GeneralRe: reverse division to convert decimals to dinary Pin
CPallini1-Nov-09 10:13
mveCPallini1-Nov-09 10:13 
GeneralRe: reverse division to convert decimals to dinary Pin
Omegaclass1-Nov-09 12:28
Omegaclass1-Nov-09 12:28 
AnswerRe: reverse division to convert decimals to dinary Pin
David Crow2-Nov-09 4:08
David Crow2-Nov-09 4:08 
GeneralRe: reverse division to convert decimals to dinary Pin
Omegaclass2-Nov-09 17:15
Omegaclass2-Nov-09 17:15 
QuestionRe: reverse division to convert decimals to dinary Pin
David Crow3-Nov-09 2:44
David Crow3-Nov-09 2:44 
AnswerRe: reverse division to convert decimals to dinary Pin
Omegaclass3-Nov-09 19:08
Omegaclass3-Nov-09 19:08 
QuestionUgly Numbers Error Pin
anollipian31-Oct-09 14:21
anollipian31-Oct-09 14:21 
AnswerRe: Ugly Numbers Error Pin
LunaticFringe31-Oct-09 14:30
LunaticFringe31-Oct-09 14:30 
GeneralRe: Ugly Numbers Error Pin
anollipian31-Oct-09 14:44
anollipian31-Oct-09 14:44 
GeneralRe: Ugly Numbers Error Pin
Luc Pattyn1-Nov-09 3:59
sitebuilderLuc Pattyn1-Nov-09 3:59 
QuestionRe: Ugly Numbers Error Pin
David Crow31-Oct-09 16:26
David Crow31-Oct-09 16:26 
Question2 Errors Pin
MrMcIntyre31-Oct-09 6:09
MrMcIntyre31-Oct-09 6:09 
AnswerRe: 2 Errors Pin
Chris Losinger31-Oct-09 6:10
professionalChris Losinger31-Oct-09 6:10 
AnswerRe: 2 Errors Pin
enhzflep31-Oct-09 6:17
enhzflep31-Oct-09 6:17 
GeneralRe: 2 Errors Pin
MrMcIntyre31-Oct-09 6:25
MrMcIntyre31-Oct-09 6:25 
GeneralRe: 2 Errors Pin
enhzflep31-Oct-09 6:36
enhzflep31-Oct-09 6:36 

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.