Click here to Skip to main content
16,016,425 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Looking for opinions on currency handling.... Pin
CPallini3-Sep-24 3:07
mveCPallini3-Sep-24 3:07 
GeneralRe: Looking for opinions on currency handling.... Pin
Jeremy Falcon3-Sep-24 3:23
professionalJeremy Falcon3-Sep-24 3:23 
GeneralRe: Looking for opinions on currency handling.... Pin
Mircea Neacsu3-Sep-24 15:45
Mircea Neacsu3-Sep-24 15:45 
GeneralRe: Looking for opinions on currency handling.... Pin
Jeremy Falcon3-Sep-24 15:50
professionalJeremy Falcon3-Sep-24 15:50 
GeneralRe: Looking for opinions on currency handling.... Pin
Jeremy Falcon3-Sep-24 15:53
professionalJeremy Falcon3-Sep-24 15:53 
GeneralRe: Looking for opinions on currency handling.... Pin
Mircea Neacsu3-Sep-24 16:07
Mircea Neacsu3-Sep-24 16:07 
GeneralRe: Looking for opinions on currency handling.... Pin
Jeremy Falcon3-Sep-24 17:31
professionalJeremy Falcon3-Sep-24 17:31 
QuestionADDENDUM How to display full 4 binary bits - after QString "number" option converts string to int. including hexadecimal strings. Pin
jana_hus30-Aug-24 7:39
jana_hus30-Aug-24 7:39 
Addendum

I have settled on the following ( the example is for converting MSB ) , still convoluted ,code.

I would like to find out , discuss , the usage of "toLongLong" .


C++
QString binaryNumber = QString::number(hexadecimalNumber.toLongLong(&ok, 16), 2).rightJustified(4,'0').leftJustified(8,'0');









Up front
I am very sorry to reopen this post.
For information, I am leaving the original post (code).

I have an additions issue, I need help with to correct.

This code snippet correctly converts string "42"
to binary code "01000000".

I do not need more help with that conversion,
BUT in need help converting when
the string contains hexadecimal value, such as "F9".

Changing "toInt(),2)" options to toInt(),16) does not do the job.

I realize that the Qt code is little convoluted and for this reason -
May I suggest that only coders with experience of Qt take a look at this ?

No, it is not an instruction how to reply, just a suggestion.










C++
pFT857_library->CAT_Data_String[CAT_Data_Index].mid(0,1).number(pFT857_library->CAT_Data_String[CAT_Data_Index].mid(0,1).toInt(),2).leftJustified(7,'0');






Solution :

pFT857_library->CAT_Data_String[CAT_Data_Index].mid(0,1).number(n,2).rightJustified(4,'0');

Output :

" convert LSB to binary with leading zeroes "
"0001"



C++
I have Qt style string QString frequency = "1426000" split into another QString as 
QString frequency_array = "01 42 60  00" 
I need to change each pair as 8 bit binary with 
MSD as upper 4 bits of the 8 bit word
AND 
LSD as lower 4 bits of the 8 bit word

For debugging purpose I like to print each step of the conversion.

As an example , I like to see "42 "
as
"01000010" 

I prefer Qt QString  in C++ code

Here is my code so far 



```
    for (int index = 0; index <6 ; index++)
    {
    text = pFT857_library->CAT_Data_String[index];
    m_ui->lineEdit_14->setText(text);
    qDebug() << text;
    text = text.mid(0,1).toLocal8Bit();
    qDebug() << text;

    text = pFT857_library->CAT_Data_String[index];
    text = text.mid(1,1).toLocal8Bit();
    qDebug() << text;

    }

```




The above WAS my initial post / code and I have dropped the post.

My current code is little over-documented so I am hesitant to post it.

However,
I have a (simple_) question.
Using the following snippet

C++
int n =  pFT857_library->CAT_Data_String[CAT_Data_Index].toInt();
    text = pFT857_library->CAT_Data_String[CAT_Data_Index].number(n,2);
    qDebug() << text;
q



I can visualize the binary representation of the string - that is partially my goal.
My question is - how do I visualize FULL 4 bits of the desired info.
"number" with option "2" "prints" all valid bits BUT I need full
length of 4 bits - including "leading zeroes".

Example
"number" prints "100" representing decimal 4
I need
"0100" - full 4 bits.

modified 6-Sep-24 15:33pm.

QuestionRe: How to display full 4 binary bits - after QString "number" option converts string to int. Pin
Richard MacCutchan30-Aug-24 8:05
mveRichard MacCutchan30-Aug-24 8:05 
AnswerRe: REOPEN How to display full 4 binary bits - after QString "number" option converts string to int. including hexadecimal strings. Pin
Richard MacCutchan3-Sep-24 21:56
mveRichard MacCutchan3-Sep-24 21:56 
Questionwrapping enum in namespace ? Pin
Maximilien29-Aug-24 3:37
Maximilien29-Aug-24 3:37 
AnswerRe: wrapping enum in namespace ? Pin
k505429-Aug-24 5:43
mvek505429-Aug-24 5:43 
GeneralRe: wrapping enum in namespace ? Pin
Maximilien29-Aug-24 6:41
Maximilien29-Aug-24 6:41 
QuestionThis should be an easy question... 128-bit blues. Pin
Jeremy Falcon28-Aug-24 11:12
professionalJeremy Falcon28-Aug-24 11:12 
AnswerRe: This should be an easy question... 128-bit blues. Pin
k505428-Aug-24 12:04
mvek505428-Aug-24 12:04 
GeneralRe: This should be an easy question... 128-bit blues. Pin
Jeremy Falcon28-Aug-24 12:21
professionalJeremy Falcon28-Aug-24 12:21 
AnswerRe: This should be an easy question... 128-bit blues. Pin
Mircea Neacsu28-Aug-24 14:47
Mircea Neacsu28-Aug-24 14:47 
GeneralRe: This should be an easy question... 128-bit blues. Pin
Jeremy Falcon28-Aug-24 15:03
professionalJeremy Falcon28-Aug-24 15:03 
GeneralRe: This should be an easy question... 128-bit blues. Pin
Mircea Neacsu28-Aug-24 15:11
Mircea Neacsu28-Aug-24 15:11 
GeneralRe: This should be an easy question... 128-bit blues. Pin
Jeremy Falcon28-Aug-24 15:43
professionalJeremy Falcon28-Aug-24 15:43 
GeneralRe: This should be an easy question... 128-bit blues. Pin
Mircea Neacsu28-Aug-24 15:46
Mircea Neacsu28-Aug-24 15:46 
QuestionOwn border in client area Pin
john563226-Aug-24 19:59
john563226-Aug-24 19:59 
AnswerRe: Own border in client area Pin
Richard MacCutchan26-Aug-24 22:10
mveRichard MacCutchan26-Aug-24 22:10 
AnswerRe: Own border in client area Pin
Maximilien27-Aug-24 8:22
Maximilien27-Aug-24 8:22 
QuestionData file Pin
Calin Negru26-Aug-24 2:36
Calin Negru26-Aug-24 2: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.