小编she*_*ngy的帖子

缩小数字的好方法

可能重复:将
21个字母数字字符压缩为16个字节

我有8个号码

有没有办法将它转换为长度为4的字符串?

例如:

输入 12345678

产量 AB2D

转换应该能够准确转换回来.

我试图将它转换为32 Hex,但它仍然有5个数字,我不能0 1 O I在最后的字符串中使用.有什么好的建议吗?顺便说一句,只能使用大写字母.

c c++ java algorithm

3
推荐指数
1
解决办法
860
查看次数

哪种工具可以提取这种评论?

嗨,我最近发现在代码中有一些特殊的注释,但它不是doxygen风格,谁能告诉我什么工具可以提取这种评论?

/*
 @doc INTERNAL
 @func  ULONG | SerialDispatchThread | Main serial event dispatch thread code.
 *  This is the reading and dispatching thread. It gets the
 *  event associated with the logical interrupt dwIntID and calls
 *  hardware specific routines to determine whether it's a receive event
 *  or a transmit event. If it's a transmit event, it calls the HW tx handler.
 *  If it's a receive event, it calls for the number of characters and calls
 *  atomic …
Run Code Online (Sandbox Code Playgroud)

c comments

3
推荐指数
1
解决办法
85
查看次数

C中的无符号和有符号值

这是一个问题:

在"计算机系统:程序员的视角"一书中2.2.5

它表示如果无符号值与有符号值进行比较,则将以非换行格式比较所有值.像这样

if(-1 < 0u)
{
    // will not print this line because -1 will be translated to 255.
    printf("all changed to unsigned format");
}
Run Code Online (Sandbox Code Playgroud)

我在VC6 SP6中尝试了这个代码,字符串没有输出.一切看起来都很好,因为我们都知道-1被翻译为255.

但是当我读到"Expert C Programming Deep C Secrets"一书1.10时

它说如果我的编译器使用ANSI C标准,则此代码将打印"-1 <(unsigned char)1:ANSI":

if(-1 < (unsigned char)1)
{
    printf("-1 < (unsigned char)1: ANSI");
}
else
{
    printf("-1 NOT Less than (unsigned char)1: K&R");    
}
Run Code Online (Sandbox Code Playgroud)

我得到的输出是:-1 <(unsigned char)1:ANSI.

我正在使用VC6 SP6编译器.

为什么会这样?

根据"计算机系统:程序员的视角"一书

-1 <(unsigned char)1将-1转换为无符号值.所以它会变成这样的:

255 <1

这不应该打印出行-1 <(unsigned char)1:ANSI.

任何人都可以告诉我为什么会这样吗?

c unsigned signed

2
推荐指数
1
解决办法
1984
查看次数

这个"新"语法是什么意思?

最近我读了一段这样的代码:

template <unsigned long size>
class FooBase
{
  bool m_bValid;
  char m_data[size];
};

template <class T>
class Foo : public FooBase<sizeof(T)>
{
  // it's constructor
  Foo(){};
  Foo(T const & t) {construct(t); m_bValid = (true);}

  T const * const GetT() const { return reinterpret_cast<T const * const>(m_data); }
  T * const GetT() { return reinterpret_cast<T * const>(m_data);}

  // could anyone help me understand this line??
  void construct(T const & t) {new (GetT()) T(t);}
};
Run Code Online (Sandbox Code Playgroud)

我已经对代码进行了切片以确保它并不复杂,主要问题是关于construct(T const & t)函数.

什么 …

c++ syntax new-operator

2
推荐指数
1
解决办法
271
查看次数

为什么operator =()函数不能由derive类继承

可能重复:
在C++中继承operator =的麻烦

我更新了代码

#include <QtCore/QCoreApplication>

class Base
{
    int num;
public:
    Base& operator=(int rhs)
    {
        this->num = rhs;
        return *this;
    }
};

class Derive : public Base
{
public:
    int deriveNum;
    using Base::operator =; // unhide the function
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    Base base;
    Derive derive1, derive2;

    base = 1;  // calls Base::operator(1) and returns Base&

    derive1 = 11; // calls Base::operator(11) and returns Base&
    derive2 = 22; // calls Base::operator(22) and returns …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance operator-keyword

1
推荐指数
1
解决办法
355
查看次数

wxpython的wxEvent.Skip()解释道

我最近学习wxPython通过wxPython in Action,但我被困在第3章,特别是对的解释Figure 3.3Skip()钻石

Step 3 Locating the binder object,书中写道:

如果没有找到对象本身的绑定器,则处理在类层次结构中向上查找在对象的超类中定义的绑定 - (1)这与在容器层次结构中的向上走动不同下一步.

但在下一步中,Step 4 Determining whether to continue processing写道:

事件处理程序通过调用wx.Event方法Skip()来请求更多处理.如果调用Skip()方法,则继续处理,并且(2)在步骤中找到并执行在(3)超类中定义的任何处理程序.可以在处理程序中的任何位置调用Skip()方法.Skip()方法在事件实例中设置一个标志,wxPython在处理程序方法完成后进行检查.在清单3.3中,OnButtonClick()不调用Skip(),因此在这种情况下,事件处理在处理程序方法结束时完成.另外两个事件处理程序会调用Skip()(4),因此系统将继续搜索匹配的事件绑定,(5)最终调用鼠标进入和离开事件的默认功能,例如鼠标悬停事件.

我的问题与我在段落中标记的数字有关:

(1)在我的理解和其他一些googled材料中,传播是在容器层次结构中发生的事情,而不是类层次结构,这是正确的吗?

(2)说真的吗?任何处理程序都被执行?不是匹配实例和事件组合的那些?

(3)这里的超类是否正确?不应该是父窗户吗?

(4)我认为这一行与question2相矛盾,所以也许没有执行任何处理程序,只是匹配实例和事件组合的处理程序?

(5)什么是default functionality?它是如何被调用的?

如果有人有兴趣,list-3.3.py就在这里:

import wx


class MouseEventFrame(wx.Frame):

    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, 'Mouse Events',
                          size=(300, 200))
        self.panel = …
Run Code Online (Sandbox Code Playgroud)

python events wxwidgets wxpython

1
推荐指数
1
解决办法
3717
查看次数

使用itoa()的最佳做法是什么

当我使用itoa()它需要一个char*_DstBuff,这里最好的做法是什么?

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
  int num = 100;

  // I'm sure here is no memory leak, but it needs to know the length.
  char a[10]; 

  // will this causue memory leak? if yes, how to avoid it?
  // And why can itoa(num, b, 10); be excuted correctly since b
  // has only allocated one char.
  char *b = new char; 

  // What is the difference between char *c and char *b
  // both …
Run Code Online (Sandbox Code Playgroud)

c++ memory-leaks memory-management itoa

0
推荐指数
1
解决办法
5177
查看次数

后缀前缀++和二元和运算符的优先级

我对C中的postfix和前缀运算符优先级感到困惑,任何帮助和提示都会有所帮助.

我会在这里粘贴我的测试代码:

#include <stdio.h>

int a = 0;

int main(int argc, char *argv[])
{
   if (++a & 0x01) // prefix version
   // if (a++ & 0x01) // postfix version
   {
      printf("++ first\n");
   }
   else
   {
      printf("& first\n");
   }
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

我现在可以理解,在postfix版本中,虽然postfix ++有一个更大的优先级,但是a++会返回0到这里&,0x01并且会a在此表达式后增加值.

但我无法理解的是为什么在前缀版本中,为什么++a首先进行评估?运算符优先级表指示prefix ++&具有相同的优先级,此外,它们的关联性为right-to-left.这种方法&不应该先评估吗?

编辑: 我正在使用的图表:C运算符优先表

c operator-precedence prefix-operator postfix-operator

0
推荐指数
1
解决办法
984
查看次数